DynamoDB replication

AWS DynamoDB does not follow the same architecture as the Dynamo paper.

If you use standard DynamoDB within a single-region, you get single-leader replication. This means that:

  • One leader node handles all the writes.
  • The writes are copied to follower nodes asynchronously.
  • If you send two concurrent writes for the same PK+SK, you need to:
    • either use optimistic locking strategy to prevent the conflict from happening. (In summary, you need to add a version attribute to each item, and send Conditional Writes)
    • or use a pessimistic locking strategy to prevent the conflict from happening. (In summary, you send a Transaction that will abort if someone else is modifying one of those items)

If you use DynamoDB with global tables enabled, it becomes a multi-active database. This means that:

  • You get one leader node per region.
  • The writes sent to the leader node in one region will be automatically replicated to the nodes in the other regions asynchronously using DynamoDB streams.
  • If you send two concurrent writes for the same PK+SK to two different regions, DynamoDB will use the last write wins strategy to solve the write conflict, so it’s possible to lose some writes. Neither optimistic locking nor pessimistic locking will protect you. A transaction sent to one region will not mean a transaction in the other regions: since the changes are replicated using DynamoDB stream, the “transaction” aspect is lost.
DynamoDB replication

Leave a comment