user855
user855

Reputation: 19918

DynamoDB - Global tables conflict resolution

Conflicts can arise if applications update the same item in different regions at about the same time. To ensure eventual consistency, DynamoDB global tables use a “last writer wins” reconciliation between concurrent updates, where DynamoDB makes a best effort to determine the last writer. With this conflict resolution mechanism, all of the replicas will agree on the latest update, and converge toward a state in which they all have identical data.

This is what the AWS docs say. I am don't understand how "last writer wins" policy can lead to a consistent global database?

E.g.

  1. Region 1 gets write order T1 (set value to 0) T2 (set value to 5)
  2. Region 2 gets write order T2 (set value to 5) T1 (set value to 0)

The records are applied in different order in 2 places and the end result is different. Region 1 has value 5 and Region 2 has value 0.

Is this really what DynamoDB does?

Upvotes: 3

Views: 3140

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179124

I would say "no." Not as you described it.

Conflict resolution only applies in a situation where T1 is a direct write to region 1 that subsequently replicates to region 2... and T2 is a near-concurrent direct write to the same item (different data) in region 2 that subsequently replicates to region 1.

What you described is out-of-order replication of writes sent initially to a single region, which isn't an issue, because replication itself happens in order. Global Tables replication uses DynamoDB Streams, which captures a time-ordered sequence of item-level modifications.

If your application only ever writes to a single region, no conflicts in this sense can occur, because any other regions will always see the updates replicate in order.

The "last writer wins" means that when the update T2, written directly to R2, arrives at R1 via replication, R1 sees that T2 occurred later in time than T1, and applies it at R1... but when the update T1, written directly to R1, arrives at R2 via replication, R2 sees that it occurred earlier in time than T2 and discards it (does not apply it at R2), because T2 was the last write to occur (in time).

Upvotes: 4

Related Questions