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: Dr.-Otto-Bâßner-Weg 7a, Ottobrunn, Bavaria 85521

AWS for the Real World

Join our community of over 8,800 readers delving into AWS. We highlight real-world best practices through easy-to-understand visualizations and one-pagers. Expect a fresh newsletter edition every two weeks.

Read more from AWS for the Real World

βŒ› Reading time: 17 minutes πŸŽ“ Main Learning: Observability at Scale with Open-Source πŸ‘Ύ GitHub Repository ✍️ Read the Full Post Online πŸ”— Hey Reader πŸ‘‹πŸ½ Welcome to this edition of the AWS Fundamentals newsletter! In this issue, we're focusing on observability with open-source tools on AWS. As most of you already know, we can use Amazon CloudWatch and X-Ray to monitor our application from every angle. But what if we want to hybrid setup where we run certain parts of our ecosystem outside of AWS?...

βŒ› Reading time: 9 minutes πŸŽ“ Main Learning: Polling or WebSockets: Choosing with Amazon API Gateway πŸ‘Ύ GitHub Repository ✍️ Read the Full Post Online πŸ”— Hey Reader πŸ‘‹πŸ½ What would you use for quick and regular data updates inside your web app? Or let's phrase it another way: how would you choose between Polling and WebSockets? πŸ’­ Understanding the nuances between these two communication methods is important, as they both come with their own advantages, gotchas, and side effects that are not very...

βŒ› Reading time: 10 minutes πŸŽ“ Main Learning: Building a Serverless Platform With SST, Lambda & Next.js ✍️ Read the Full Post Online πŸ”— Hey Reader πŸ‘‹πŸ½ In this post, we want to guide you through our complete setup for our custom video platform. Our CloudWatch Book's Video Section This starts from the purchase to actually accessing our custom build video-access platform. Overview about our CloudWatch Book Landing Page & Video Platform Architecture We'll explain why we decided against a third-party...