DEV Community

Cover image for Introduction to Amazon DynamoDB
Boyilla Ramani
Boyilla Ramani

Posted on

Introduction to Amazon DynamoDB

What is Amazon DynamoDB?

Image description

Amazon DynamoDB is a fully managed NoSQL database service provided by Amazon Web Services (AWS) that offers fast and predictable performance with seamless scalability. It allows developers to offload the administrative burdens of operating and scaling distributed databases, enabling them to focus on their applications. DynamoDB can handle large amounts of data and high request rates, making it suitable for applications requiring consistent, single-digit millisecond latency at any scale.

Why DynamoDB?

Amazon DynamoDB is a serverless, NoSQL database service that allows you to develop modern applications at any scale. As a serverless database, you only pay for what you use and DynamoDB scales to zero, has no cold starts, no version upgrades, no maintenance windows, no patching, and no downtime maintenance. DynamoDB offers a broad set of security controls and compliance standards. For globally distributed applications, DynamoDB global tables is a multi-Region, multi-active database with a 99.999% availability SLA and increased resilience. DynamoDB reliability is supported with managed backups, point-in-time recovery, and more. With DynamoDB streams, you can build serverless event-driven applications.

Key features of Amazon DynamoDB

1. Scalability: Automatically scales up and down to adjust for capacity and maintain performance.
2. Performance: Provides consistent, single-digit millisecond response times.
3. Managed Service: Automates administrative tasks such as hardware provisioning, setup, configuration, replication, software patching, and backups.
4. Security: Offers encryption at rest and in transit, and integrates with AWS Identity and Access Management (IAM) for fine-grained access control.
5. Global Tables: Provides a fully managed solution for deploying a multi-region, fully replicated database.
6. Streams: Captures data modification events in DynamoDB tables and allows applications to respond in real-time.
7. Integrated with other AWS services: Easily integrates with AWS Lambda, Amazon Redshift, Amazon S3, and other AWS services.

Benefits of DynamoDB

Serverless performance with limitless scalability

  1. Key-value and document data models
  2. Serverless that scales to zero
  3. ACID transactions
  4. Active-active replication with global tables
  5. DynamoDB Streams as part of an event-driven architecture
  6. Secondary indexes

Security and reliability

  1. Fine-grained access control
  2. Encryption at rest
  3. Point-in-time recovery
  4. On-demand backup and restore
  5. Private network connectivity

Cost-effectiveness
Read/write capacity modes
On-demand mode
Standard Infrequent Access (Standard-IA) table class
Auto scaling for improved cost efficiencies

Integrations with AWS services

  1. Bulk import and export from Amazon S3
  2. Advanced streaming applications with Kinesis Data Streams for DynamoDB
  3. Monitoring and diagnosing system performance with Cloudwatch

Scale and value of DynamoDB

Image description

Amazon DynamoDB solutions by industry

1. Financial services

Image description
Financial services customers choose DynamoDB for resiliency, security, performance, and scalability. DynamoDB helps customers achieve industry regulatory compliances such as SOC 1/2/3, PCI, FINMA, and ISO. Discover how DynamoDB can power your use cases such as fraud detection, messaging workflows, digital user onboarding, and more.

2. Media & Entertainment

Image description
Media and Entertainment customers choose Amazon DynamoDB for scalability, performance, and resiliency. DynamoDB helps customers manage their streaming and content metadata access needs with nearly unlimited throughput. Discover how Amazon DynamoDB can power your use cases such as creating a digital human to livestream content, migrating your digital content to the cloud, and more.

3. Advertising & Marketing

Image description
Advertising & Marketing customers choose Amazon DynamoDB for security, performance, and resiliency. DynamoDB helps customers achieve data fidelity by storing various marketing data such as user profiles, user events, clicks, and visited links. Discover how Amazon DynamoDB can power your use cases such as evaluating social media posts, monetizing publishing assets more effectively, real-time bidding, ad-targeting, and attribution.

4. Retail & Wholesale

Image description
Retail & Wholesale customers choose Amazon DynamoDB for scalability, performance, resilience, and security. DynamoDB helps customers handle their high-traffic, extreme-scaled events seamlessly with nearly unlimited throughput. Discover how Amazon DynamoDB can power your use cases such as localizing content, building a well-architected customer data platform, deploying shopping carts, tracking inventory, and more.

Core components of Amazon DynamoDB

Tables, items, and attributes

Image description
The following are the basic DynamoDB components:

Tables – Similar to other database systems, DynamoDB stores data in tables. A table is a collection of data. For example, see the example table called People that you could use to store personal contact information about friends, family, or anyone else of interest. You could also have a Cars table to store information about vehicles that people drive.

Items – Each table contains zero or more items. An item is a group of attributes that is uniquely identifiable among all of the other items. In a People table, each item represents a person. For a Cars table, each item represents one vehicle. Items in DynamoDB are similar in many ways to rows, records, or tuples in other database systems. In DynamoDB, there is no limit to the number of items you can store in a table.

Attributes – Each item is composed of one or more attributes. An attribute is a fundamental data element, something that does not need to be broken down any further. For example, an item in a People table contains attributes called PersonID, LastName, FirstName, and so on. For a Department table, an item might have attributes such as DepartmentID, Name, Manager, and so on. Attributes in DynamoDB are similar in many ways to fields or columns in other database systems.

The following schema shows a table named People with some example items and attributes.

People

{
    "PersonID": 101,
    "LastName": "Smith",
    "FirstName": "Fred",
    "Phone": "555-4321"
}

{
    "PersonID": 102,
    "LastName": "Jones",
    "FirstName": "Mary",
    "Address": {
                "Street": "123 Main",
                "City": "Anytown",
                "State": "OH",
                "ZIPCode": 12345
    }
}

{
    "PersonID": 103,
    "LastName": "Stephens",
    "FirstName": "Howard",
    "Address": {
                "Street": "123 Main",
                "City": "London",                                    
                "PostalCode": "ER3 5K8"
    },
    "FavoriteColor": "Blue"
}
Enter fullscreen mode Exit fullscreen mode

Secondary indexes

You can create one or more secondary indexes on a table. A secondary index lets you query the data in the table using an alternate key, in addition to queries against the primary key. DynamoDB doesn't require that you use indexes, but they give your applications more flexibility when querying your data. After you create a secondary index on a table, you can read data from the index in much the same way as you do from the table.

DynamoDB supports two kinds of indexes:

Global secondary index – An index with a partition key and sort key that can be different from those on the table.

Local secondary index – An index that has the same partition key as the table, but a different sort key.

In DynamoDB, global secondary indexes (GSIs) are indexes that span the entire table, allowing you to query across all partition keys. Local secondary indexes (LSIs) are indexes that have the same partition key as the base table but a different sort key.

Each table in DynamoDB has a quota of 20 global secondary indexes (default quota) and 5 local secondary indexes.

In the example Music table shown previously, you can query data items by Artist (partition key) or by Artist and SongTitle (partition key and sort key). What if you also wanted to query the data by Genre and AlbumTitle? To do this, you could create an index on Genre and AlbumTitle, and then query the index in much the same way as you'd query the Music table.

DynamoDB Streams

DynamoDB Streams is an optional feature that captures data modification events in DynamoDB tables. The data about these events appear in the stream in near-real time, and in the order that the events occurred.

Each event is represented by a stream record. If you enable a stream on a table, DynamoDB Streams writes a stream record whenever one of the following events occurs:

  • A new item is added to the table: The stream captures an image of the entire item, including all of its attributes.
  • An item is updated: The stream captures the "before" and "after" image of any attributes that were modified in the item.
  • An item is deleted from the table: The stream captures an image of the entire item before it was deleted.

You can use DynamoDB Streams together with AWS Lambda to create a trigger—code that runs automatically whenever an event of interest appears in a stream. For example, consider a Customers table that contains customer information for a company. Suppose that you want to send a "welcome" email to each new customer. You could enable a stream on that table, and then associate the stream with a Lambda function. The Lambda function would run whenever a new stream record appears, but only process new items added to the Customers table. For any item that has an EmailAddress attribute, the Lambda function would invoke Amazon Simple Email Service (Amazon SES) to send an email to that address.

Image description

You can use DynamoDB Streams together with AWS Lambda to create a trigger—code that runs automatically whenever an event of interest appears in a stream. For example, consider a Customers table that contains customer information for a company. Suppose that you want to send a "welcome" email to each new customer. You could enable a stream on that table, and then associate the stream with a Lambda function. The Lambda function would run whenever a new stream record appears, but only process new items added to the Customers table. For any item that has an EmailAddress attribute, the Lambda function would invoke Amazon Simple Email Service (Amazon SES) to send an email to that address.

Conclusion

Amazon DynamoDB is a fully managed NoSQL database service designed for fast, predictable performance and seamless scalability. It supports key-value and document data models, making it versatile for various applications, including financial services, media, advertising, and retail. With features like automatic scaling, ACID transactions, global tables, DynamoDB Streams, and integration with other AWS services, DynamoDB offers robust security, reliability, and cost-effectiveness. It simplifies database management, allowing developers to focus on building scalable, high-performance applications without the administrative overhead.

Top comments (0)