DynamoDB Global Tables
DynamoDB Global Tables
In this article, we will create a DynamoDB table, make it global, and test it.
Join the DZone community and get the full member experience.Join For Free
In this article, we will create a DynamoDB table, make it global, and test it. Global Table is a powerful feature but simple and easy to use.
Global Table helps the customers to deploy a multi-region, multi-master database and takes care of all necessary tasks to create identical tables in these Regions and propagate ongoing data changes to all of them.
You may also like: Indexing in DynamoDB
Where to Use Global Table?
Global Tables comes in handy for the applications having globally distributed users. This will help customer to deliver low latency data access to your distributed users
Pre-Conditions for Creating Global Tables:
- Global Tables should be of single AWS Account
- No data to be present while creating Global Dynamo DB Table
- Streaming to be enabled.
Let’s Start Creating Our Table
Here we will create a movie catalog table with some attributes. Let’s open the AWS Console and go to the Dynamo DB Services.
Hit “Create Table” from the menu.
Since we can’t create multiple databases in Dynamo DB like we used to do in RDBMS, we need to follow certain conventions for the maintenance of different tables.
I prefer prefixing the table name based on the project.
Let’s enter the table name as global_demo_moviecatalog
Add movie_id as partition key, which is of type string along timestamp as sort key.
We have 2 types of indexes:
- LSI – Local Secondary Index
- GSI – Global Secondary Index
We will create 2 LSI and 1 GSI in this example.
First LSI — movie_id and genre (sort key)
Second LSI — movie_id and title (sort key)
GSI — movie_id
Please refer to the following screenshots for the above-mentioned points.
Let’s bring down the default RCU  and WCU  to 2 each. This will help us understanding auto-scaling at a later stage.
Don't worry about the pricing. This will be covered under the free tier.
At this point, we will not be enabling auto-scaling. Go ahead and disable auto-scaling by unchecking Read and Write Capacity under the Auto Scaling Header.
Refer to the below screens for reducing the capacity and disabling Auto Scaling.
Go ahead and hit the CREATE button.
After a few seconds, you will notice that the table is created.
Global Table Steps
Now that we have created an empty table, we will proceed to make it a global table.
Go to the Global Tables tab.
You will notice a green tick to inform that we have met one of the conditions to make the table Global and another one which Enabling Streams is yet to be done.
What are we waiting for? Let’s go to the overview tab and enable streams.
In the Overview tab, under the stream details, click on Manage Stream.
Select “New and old images” and hit the Enable button
Now go back to the Global Table tab.
Click on the “ADD REGION” button.
We have added EU West as the region where we wanted to replicate the data.
You can also notice the auto-scaling attribute is set to DISABLED.
That’s it. We have created a global table spanning 2 regions [US-EAST-1 and EU-WEST].
Let’s add new items to the table and see if it works.
Go to Item tab and click the Create Item button within the US-EAST-1 region.
Change the region from US-EAST-1 to Ireland.
You can see the data entered in US-EAST-1.
Now let’s add an item in the IRELAND region.
After saving successfully, shift the region to US-EAST-1.
You can see the data entered from the IRELAND region.
I hope you can appreciate the ease with which you can create global tables.
In the next part, we will see how to enable Auto Scaling.
Opinions expressed by DZone contributors are their own.