Amazon DynamoDB

Learn about the Amazon DynamoDB, core components, backup, and recovery. Also, get an overview of DynamoDB Accelerator (DAX).

Amazon DynamoDB is a fully managed, schemaless NoSQL database service that handles all management tasks, including monitoring the hardware capacity, software updates, and patches. It offers fast and predictable performance and seamless scalability. DynamoDB automatically replicates data across three availability zones in an AWS Region to provide high availability and durability.

Press + to interact

It saves us from worrying about data protection by providing an encryption mechanism. We can scale up and down DynamoDB according to the data amount without downtime. It also supports on-demand backup, point-in-time restore, and long-term retention for regulatory compliance.

DynamoDB core components

There are three main components of Amazon DynamoDB that help to store data, maintain ordering and structure, and query the data – table, items, and attributes.

  • Tables: The table is the main entity, like we have in relational databases. It stores the data about a particular entity/thing in the form of items and maintains relations. 

  • Items: An item is a collection of attributes that describe the item’s properties. An item is unique among the other items. Items are the same as other databases’ records, rows, or tuples. In DynamoDB, we can have unlimited items in a table, and a table can exist without any item.

  • Attributes: An attribute is a building block of a table. It defines the properties and nature of an item. The type of an attribute remains the same for each item in a table. In DynamoDB, attributes can be considered as columns or fields of the other databases.

Keys and indexes

DynamoDB maintains keys and indexes to manage and organize data efficiently.

Primary key

Like other databases, DynamoDB also has primary keys. Each table in DynamoDB has a unique identifier to distinguish between the table items. A primary key supports only string, number, or binary type. DynamoDB has two types of primary keys: partition and composite, as shown in the following illustration:

Press + to interact
Types of primary keys
Types of primary keys

The partition key consists of a single attribute, while the composite key consists of a partition and a sort key. A partition key as a primary key distinguishes each entry or record in a table uniquely. The partition key’s value is used to query the internal hash function to get the partition of the actual memory in DynamoDB, where the data resides. Where a composite key is used as a primary key, all the data for a particular partition key is kept together and sorted by the sort key’s value.

Secondary indexes

DynamoDB allows us to query over the non-key attributes by creating secondary indexes. There are two types of secondary indexes: The global and local secondary indexes. In the global secondary index, we can specify partition and sort keys different than the primary keys of the table, while in the local secondary index, the partition key for the index remains the same as that of the table but with a different sort key.

Data consistency models

DynamoDB has two read consistency models; users can select the model based on their scenario. Let’s have a brief view of these models.

  • Eventually consistent read (default): This model ensures high read throughput but does not return the results from the latest write operations. However, making the read operation again after a few seconds includes the latest data.

  • Strongly consistent read: This read model ensures to include the results from all the successful write requests before the read operation.

DynamoDB also supports ACID transactions across tables within a single AWS account and region.

Global tables and multi-region replication

Global tables are fully managed, multi-region, and multi-active replicas for DynamoDB. They are used to:

  • Replicate data across AWS Regions

  • Achieve high availability and durability

  • Migrate data from one AWS Region to another

  • Provide resilience and help in disaster recovery

  • Deploy applications having global users

DynamoDB allows us to create multi-region replicas using global tables. We can select any AWS Region from the available list, but the ideal regions are the ones that are nearer to our users or best for our application. DynamoDB creates a global table in the selected region and replicates the ongoing changes synchronously. This makes the DynamoDB tables highly available in the event of an outage in the region.

Press + to interact
High level archtecture of global tables that offer multi-active replication across regions
High level archtecture of global tables that offer multi-active replication across regions

Backup in DynamoDB

DynamoDB offers an on-demand complete backup facility for the tables. This backup can be retained long-term or achieved for regulatory compliance purposes. The backup and restore processes don’t affect the performance of the tables. There are two methods available to create on-demand backup.

  • AWS Backup service: AWS Backup is a fully managed service that facilitates automating and centralizing backups across AWS services in the cloud or on-premises. This is a native option for backups in DynamoDB.

  • DynamoDB backups: We can also create on-demand backups from the DynamoDB dashboard on the AWS Management Console.

To restore the on-demand backup created using AWS Backup to another AWS Region or account, we need to copy the backup to that region or account first then we can restore it.

Point-in-time recovery (PITR)

DynamoDB also has the facility to take continuous backup using a point-in-time recovery option. PITR is an incremental backup, allowing us to restore tables to any particular state with a minimum of 5 minutes from the current time during the retention period. We can set the value of the retention period from 1 to 35 days.

DynamoDB Accelerator (DAX)

DynamoDB Accelerator is a caching solution for DynamoDB tables. It’s a fully managed service that enhances the performance of DynamoDB by providing microsecond response time. It is useful for scenarios where fast retrieval of eventually consistent data is required. It saves cost by excluding the need to provision extra resources and brings frequently accessed data into the memory for better performance.

DAX is a cluster of cache nodes (one primary and the other are read replicas) that resides between the application and the DynamoDB. It’s a VPC-based resource and always runs in a VPC. When the application generates API requests, they are routed toward the DAX cluster. The data is returned to the application if the DAX cluster fulfills the request. Otherwise, the request is passed to the DynamoDB tables.

Press + to interact
High level architecture of DAX
High level architecture of DAX

Get hands-on with 1300+ tech skills courses.