suitianshi
suitianshi

Reputation: 3340

What happens if i write to DynamoDb data after a stale read?

Let's say I'm using eventually consistent read mode. After my first write to a key with value {"name":"Bob", "age":"1"}, my read happens to return stale data from a replica (old value {"name":"Bob", "age":"0"}), and then i make a second write (based on this stale read) with value {"name":"Cat", "age":"0"}.

Then what happens in DynamoDb side?

  1. it rejects my second write
  2. it updates with the value {"name":"Cat", "age":"0"}
  3. it updates with the value {"name":"Cat", "age":"1"}

If no.3 is correct behavior, then how it works behind the scenes? And how it knows that i didn't intentionally make the age as 0?

Upvotes: 0

Views: 687

Answers (1)

karjan
karjan

Reputation: 1016

From your answers it's no.2. By default, DynamoDB has eventually consistent reads, but writes are always strongly consistent.

The way it works:

  • You always get 3 nodes, 1 for writes, 2 for reads
  • On write, you send the request. Data is written to write node and synchronously replicated to one of read nodes. At this point you get a response.
  • Data is asynchronously replicated between read nodes
  • When you make a read, you have 50% chance of performing strongly consistent read (if you target, the node that had synchronous write)

Upvotes: 0

Related Questions