DynamoDB Cross-Region Replication with Global Tables

Learn via video courses
Topics Covered

Overview

As a feature of Amazon Web Services, Amazon offers the cloud database service Amazon DynamoDB (AWS), a fully-managed, proprietary NoSQL database with several benefits that supports key-value and document-based database paradigms. We will learn about DynamoDB Cross Region Replication with Global Tables in this article.

How to replicate data seamlessly across regions with Global Tables

For example, let us assume you have a sizable customer base dispersed across the US, Europe, and Australia. Using their application, these consumers can change the information on their profiles. To fulfill this circumstance, you must create three equivalent ConsumerProfiles DynamoDB tables in the three distinct AWS Regions where the customers are situated. Changes to the data in one table would not be replicated in the other two, as these three tables would be completely independent. You would have to create and write code to duplicate the data changes if you didn't have a managed replication solution. However, carrying this out would take a lot of time and work.

Rather than writing code, you might construct a global database that contains your three region-specific ConsumerProfiles tables. For updates to ConsumerProfiles data in one region to quickly spread to the other regions, DynamoDB would then automatically replicate data changes among those tables. Your customers may still access the identical ConsumerProfiles data in the other AWS regions if one of them were to suddenly stop working.

Each replica can use a separate table class to optimize cost and performance if the replicas in various regions have different access patterns. For instance, a replica with rare access can use the DynamoDB Standard-Infrequent Access table class, while replicas with frequent access to data can use the DynamoDB Standard table class, where throughput is the primary cost.

Providing security and access for your Global Tables with AWS KMS

  • Using the AWSServiceRoleForDynamoDBReplication service-linked role with the customer-managed key or the AWS-managed key which are used to encrypt the replica, you can execute AWS KMS actions on your global tables.
  • DynamoDB will remove a replica from the replication group if the customer-managed key used for encrypting the replica is not accessible. After 20 hours of the KMS key being detected as unreachable, the replica won't be erased, and replication from and to this area will halt.
  • If the key is no longer being used to encrypt a replica table, you should disable the customer-managed key used for that purpose. You need wait for the deletion operation to finish and the Global Table must first become "active" before the key is disabled; after sending a command to delete a replica table. Partial data replication from and to the replica table could occur if this is not done.
  • You must modify/update or delete your IAM role policy for the replica table while it is in the Active state. If you choose not to do this, the replica table could be unsuccessfully created, updated, or deleted.

Setting up DynamoDB Replication using Global Tables

AWS regions are the distinct geographic areas where AWS compute resources are housed. A logical grouping of data centers called an availability zone makes up each area. You can easily set up DynamoDB replication using the multi-region architecture and duplicate your data using the Global Tables.

Understanding DynamoDB Global Tables:

Deploying a multi-region, multi-master DynamoDB replication solution is possible with DynamoDB Global Tables. Users do not need to develop their own code to change the data because it is a completely managed solution. DynamoDB automatically updates the data before being replicated across several regions. Applications with a worldwide user base should use Global Tables. Customers are served based on their proximity to a specific region, reducing latency and enhancing application performance. It also uses the multi-master paradigm to facilitate write/read operations across a wide range of geographic locations.

DynamoDB Global Tables are currently available in two versions: Version 2019.11.21 (current) and Version 2017.11.29. Version 2019 is advised for all new implementations since it offers capabilities like adding new replica tables even when the database is already filled with data (not empty). Version 2019 is more cost-effective and uses less writing capacity; thus, there are fewer expenses.

Using the AWS Console to set up Multi-Region Replication in DynamoDB:

DynamoDB streams are used by Global Tables to transfer changes between replicas. A mechanism for the flow of information about item changes in a DynamoDB table is called DynamoDB Streams. There are several ways to set up Multi-Region DynamoDB Replication, including utilizing Java to generate Global Tables, the AWS Console, and the Amazon Command Line. The Global Tables will be created using the AWS Console in this way. You can review the official documentation here, if you wish to create the Global Tables using Java or the Amazon Command Line.

To set up Multi-Region DynamoDB Replication and build Global Tables using the AWS Console, you need to create Global Tables using the AWS Console and add regions to set up DynamoDB Replication.

Steps:

  • Log in to the AWS Account using your credentials and open the DynamoDB Console.
  • Select the Create table option on the right side corner of the console.
  • Provide a Tablename and a Partition key. Note that the partition key is a part of the table's primary key.
  • You can customize the table settings or choose to set the default settings of the table.
  • You can click the Create table button, and your table gets created.

Using the AWS Console

  • When you navigate to the 'Export and streams' option, you will observe that the DynamoDB stream is disabled.

Using the AWS Console

  • Move to the 'Global tables' option and choose 'Create replica.'

Using the AWS Console

  • Select the Available replication Regions from the dropdown menu and choose 'Create replica.'

Using the AWS Console

  • After the replica is successfully created, you will now observe that the DynamoDB stream is enabled.

Using the AWS Console

  • The replica will be successfully created in the chosen region.

Using the AWS Console

  • By carrying out the same procedure again, you can add new regions.

Conclusion

  • To summarize, we have seen how to set up Multi-Region Replication in DynamoDB with Global Tables. It offers a succinct introduction to a variety of related ideas, assisting users in better understanding them and applying them to accomplish data replication and recovery in the most effective manner. While you may set up DynamoDB replication using the Global Tables method, as detailed in this article, it is highly labor-intensive and necessitates in-depth technical knowledge.