Global Table In DynamoDB

Global Table In DynamoDB

Global Table in DynamoDB

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog posts, we have discussed Point In Time Recovery in DynamoDB.

https://cloudaffaire.com/point-in-time-recovery-in-dynamodb/

In this blog post we are going to discuss Global Table in DynamoDB. We will also create a Global Table.

Global Table in DynamoDB

Amazon DynamoDB global tables provide a fully managed solution for deploying a multi-region, multi-master database, without having to build and maintain your own replication solution. When you create a global table, you specify the AWS regions where you want the table to be available. DynamoDB performs all of the necessary tasks to create identical tables in these regions, and propagate ongoing data changes to all of them.

To illustrate one use case for a global table, suppose that you have a large customer base spread across three geographic areas—the AMER east coast (us-east-1), the EMEA west coast (eu-west-1), and APAC north east cost (ap-northeast-1). Customers would need to update their profile information while using your application. To address these requirements, you could create three identical DynamoDB tables named CustomerProfiles, in three different AWS regions. These three tables would be entirely separate from each other, and changes to the data in one table would not be reflected in the other tables. Without a managed replication solution, you could write code to replicate data changes among these tables; however, this would be a time-consuming and labor-intensive effort.

Instead of writing your own code, you could create a global table consisting of your three region-specific CustomerProfiles tables. DynamoDB would then automatically replicate data changes among those tables so that changes to CustomerProfiles data in one region would be seamlessly propagated to the other regions. In addition, if one of the AWS regions were to become temporarily unavailable, your customers could still access the same CustomerProfiles data in the other regions.

DynamoDB global tables are ideal for massively scaled applications, with globally dispersed users. In such an environment, users expect very fast application performance. Global tables provide automatic multi-master replication to AWS regions world-wide, so you can deliver low-latency data access to your users no matter where they are located.

Global Tables Prerequisite:

  • The table must have the same partition key as all of the other replicas.
  • The table must have the same write capacity management settings specified.
  • The table must have the same name as all of the other replicas.
  • The table must have DynamoDB Streams enabled, with the stream containing both the new and the old images of the item.
  • None of the replica tables in the global table can contain any data.

If global secondary indexes are specified, then the following conditions must also be met:

  • The global secondary indexes must have the same name.
  • The global secondary indexes must have the same partition key and sort key (if present).

Next, we are going to create two tables in two different Global Tables supported region and enable replication between them.

Step 1: Create stream enabled table in eu-west-1 region.

Note: We have not included the endpoint of local dynamodb, hence the table will be created in AWS.

Step 2: Create a stream enabled table in ‘us-east-1’ region.

Step 3: Create Global table

Global Table In DynamoDB

You can also check the global table details using describe-global-table, describe-global-table-settings, and list-global-tables AWS CLI

In the AWS console, navigate to eu-west-1 or us-east-1 region to view the global table

Global Table In DynamoDB

Step 4: Insert a single record in the table of us-east-1 region

The record will be automatically replicated to eu-east-1 region.

Global Table In DynamoDB

Global Table In DynamoDB

Next, we are going to add another region (ap-northeast-1) in our existing global table setup. In order to add another region, we need to empty the global table first.

Step 5: Empty the global table and create the same table in ap-northeast-1 region.

Step 6: Add new region (ap-northeast-1) in an existing global table

Global Table In DynamoDB

Note: New region successfully added to the global table.

We can also update the global table configuration using update-global-table-settings AWS CLI.

Step 7: Delete all the three tables

Hope you have enjoyed this article. In the next blog post, we will discuss DAX in DynamoDB

To get more details on DynamoDB, please refer below AWS documentation

https://docs.aws.amazon.com/dynamodb/index.html

 

Leave a Reply

Close Menu