Mastering Global Scale: An In-Depth Look at DynamoDB Global Tables


Hey Reader πŸ‘‹πŸ½

DynamoDB is one of the most popular AWS services that requires minimal management. However, as Dr. Werner Vogels reminds us:

β€œEverything Fails All the Time.” ⚑️

Therefore, even with managed services like DynamoDB, being prepared for a regional outage is important.

The good thing: with DynamoDB Global Tables, you can easily replicate tables across multiple AWS regions. This will not only help with region outages, but it will also ensure data is closer to clients which will reduce latency.

DynamoDB Global Tables

Global Tables replicate your data across regions, offering:

  1. ⚑️ Faster Data Access: Clients in different locations access data quickly.
  2. πŸ”₯ Region Outage Preparedness: Your application remains accessible even if a region fails.

How They Work

Data replicates asynchronously across regions, maintaining availability. Conflict resolution uses a last-write-wins approach, operating on an eventually consistent model.

Note: This can lead to synchronization issues in multi-tenant applications!

Setting Up

Create a table in one region and enable replication to others via the AWS Console, CLI, or IaC tools. DynamoDB automatically handles the bidirectional replication process - you don't need to do anything else.

With SST v3, creating a table with enabled replication is as easy as this:

If replication is enabled, the streaming option is not optional. You need to enable it! πŸ’‘

Use Cases

Let's talk about the usefulness of Global Tables in-depth.

Multi-Region Applications

Global Tables are useful for applications that serve users in multiple regions, allowing them to access data quickly from the nearest location. This setup improves the user experience by reducing latency without needing to implement caching mechanisms.

As DynamoDB runs in a pay-per-use model and it works well together with other equally charged services like Lambda, having a multi-region setup often doesn’t come with high additional costs. With services like Route 53 you can easily create a multi-region application that will automatically select the closest healthy region available.

High Availability & Disaster Recovery

Global Tables help with disaster recovery by keeping copies of data in different regions. If a region has an outage (or you’ve deployed a broken update to that region), the latency-based records of Route 53 can automatically notice this and redirect requests to a health region, even if it is further away from the source.

We’ve written a detailed article about how to set this up in the past.

If you accidentally delete a replicated table (which is not easy to do), your data will still remain in the other regions.

Low-Latency Data Access

By replicating data across regions, Global Tables offer low-latency access for users worldwide. This is crucial for applications that need real-time data interaction. It achieves this without using complex caching techniques.

This architecture will always reduce response times by a few milliseconds because the application is closer to the users.

Challenges and Solutions

Everything has its challenges, and this is true for DynamoDB global tables as well.

Handling Data Conflicts

Conflicts can happen with concurrent writes in different regions. The simplest solution is to use only one region for write operations and treat all other regions as read replicas. The downside is that you'll lose multi-region high availability for writes. If the main write region goes down, your application will switch to read-only mode.

Data conflicts due to race conditions can happen in basically any multi-tenant application.

Stale Reads

Stale reads happen when an application reads data that hasn't been updated to show the latest changes because of replication delays. This can occur not only with DynamoDB global tables but with any data in a distributed system. It's also common in caches that aren't properly cleared.

In a multi-region setup with Global Tables, you can't completely avoid stale reads between regions.

However, to reduce stale reads in a single region (which can also occur!), you can use strongly consistent reads when possible. In DynamoDB, a strongly consistent read provides the most current data, showing all successful writes before the read. This ensures your application always gets the latest data, though it may result in higher latency and lower availability compared to eventually consistent reads.

Conclusion

DynamoDB Global Tables are a practical way to ensure your application remains available & responsive across multiple AWS regions.

By replicating data asynchronously, you can keep your application running smoothly even if one region experiences issues.

However, everything comes with a grain of salt πŸ§‚: you do need to manage potential challenges like data conflicts and stale reads ✌️

​

​Tobias Schmidt & Sandro Volpicella & from AWS Fundamentals​
​
Cloud Engineers β€’ Fullstack Developers β€’ Educators

You're receiving this email because you're part of our awesome community!

If you'd prefer not to receive updates, you can easily unsubscribe anytime by clicking here: Unsubscribe

​

Our address: GrΓΌnwalder Strasse 145a, Munich, Bavaria 81547

AWS for the Real World

We teach AWS for the real world - not for certifications. Join more than 10,500 developers learning how to build real-world applications on AWS.

Read more from AWS for the Real World

AWS FOR THE REAL WORLD ⏱️ Reading time: 10 minutes 🎯 Main Learning: Building and testing Lambda@Edge functions with CloudFront is complicated, as deployments can take up to 10 minutes. With LocalStack, you can build, test, and debug your Lambda@Edge functions locally! πŸ“ Blog Post πŸ’» GitHub Repository 🎬 Watch on YouTube Hey Reader πŸ‘‹πŸ½ Happy new year! We hope you had a great time with your families and loved ones 😊 We took some time off. Sandro is bridging the cold winter in Thailand (say hi if...

AWS FOR THE REAL WORLD ⏱️ Reading time: 7 minutes 🎯 Main Learning: Learn how to securely connect to your RDS database in a private subnet using an EC2 jumphost and AWS Session Manager. No SSH keys needed. πŸ“ Blog Post πŸ’» GitHub Repository 🎬 Watch on YouTube Hey Reader πŸ‘‹πŸ½ Hope you had a great Christmas with your loved ones πŸŽ„ Tobi and I spent a few days in Berlin consulting with a startup, then caught the last sunny days in Munich before winter really hits. This week: how to actually connect to...

AWS FOR THE REAL WORLD ⏱️ Reading time: 6 minutes 🎯 Main Learning: Build a central alerting approach with CloudWatch, Lambda, EventBridge, and CDK across your AWS Organization. πŸ“ Blog Post πŸ’» GitHub Repository 🎬 Watch on YouTube Hey Reader πŸ‘‹πŸ½ Welcome to the first issue after re:Invent. For everybody who was out there, I hope you came home safe & healthy. I heard re:Invent cold is a thing like Oktoberfest cold in Munich 🍻 πŸ“° This Week in AWS ⏸️AWS Lambda Durable Functions Lambda launched Durable...