User0911
User0911

Reputation: 1582

AWS Multi region ElastiCache sync

Need information on best practices for below AWS specific use case,

  1. Our Java web application is deployed in us-east-1 and us-west-2 regions.
  2. It communicates to Dynamo DB and Memcached based ElastiCache is sitting on top of Dynamo DB in both the regions.
  3. We have Dynamo DB replication enabled between us-east-1 and us-west-2.
  4. Route 53 directs API calls to the appropriate region.

Now, the issue is when we create or update a record in Dynamo DB it get's inserted in Dynamo DB and get's cached in that particular region. Record get's replicated to other regions Dynamo DB as well, but cache doesn't remain in sync since there is no replication between ElastiCache.

How do we address this issue in a best possible way?

Upvotes: 3

Views: 5171

Answers (2)

Kurt Lee
Kurt Lee

Reputation: 349

DAX is not an answer here. I'm surprised nobody is pointing out this.
Ivan is wrong about this one.

DAX is read-write-through cache indeed, but it doesn't capture data changes happens through direct access to DynamoDB (obviously), nor the data changes that happened through "other" DAX cluster.

So in this scenario,
you have 2 DAX cluster one at west-1 one at east-1, and those two clusters are totally independent. thus, if you make a data change on west-1 through DAX, that change does get propagated to east-1 on DynamoDB Table level, Not the cache(DAX) level In other words, if you update the record that had been accessed from both region, (which than cached in both DAX Cluster), you'll still get the same problem.

Fundamentally, this is the problem of syncing cache layer across different regions, which is pretty hard. if you really need it, there are some ways of doing this by making your own Kafka or Kinesis stream that keep the Cache entry changes and consumed by cache clusters in multi-regions. which is not possible with elasticache by its own now. (but it is possible if you setup lambda or EC2 for this task only) Checkout case studies from Netflix

Upvotes: 5

Ivan Mushketyk
Ivan Mushketyk

Reputation: 8285

One option as other suggested is to use DynamoDB DAX. It's a write-through cache, meaning that you do not need to synchronise database data with your cache. It happens when behind the curtains when you write data using normal DynamoDB API.

But if you want to still use ElastiCache you can use DynamoDB Streams. You can implement a Lambda function that will be triggered on every DynamoDB update in a table and write new data into ElastiCache.

This article may give you some ideas about how to do this.

Upvotes: 1

Related Questions