Search code examples
javaamazon-web-servicesamazon-dynamodbamazon-elasticache

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?


Solution

  • 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.