amazon-web-servicesamazon-dynamodbamazon-dynamodb-streams

What guarantee does dynamoDB's strongly consistent read give?


I am aware that DynamoDB has a strongly consistent read option. See Consistency Model. It states:

A strongly consistent read in Amazon DynamoDB returns a result that reflects all writes that received a successful response prior to the read. To get a strongly consistent read result, you can specify optional parameters in a request.

Just to be pedantic, what does prior mean in this context? I have a few examples, with the second and third being more interesting than the first:

Example 1 (The boring one)

In the same program, same thread, one makes a successful write request X, then a later strongly consistent read Y in the same thread will see the result made by X or a write after X.

Example 2

I have two conditional write operations Wx, and Wy that I guarantee to be ordered with respect to each other. This is done by optimistic locking (i.e. a conditional update that checks a version on the item).

Now, let's assume Wx happens before Wy. Then, if in the same thread as Wy there is a strongly consistent read operation Rz following Wy, will it see the side effects of Wx?

Example 3

I listen to a DynamoDB stream via a Lambda (see this), which sees a PutItem record W on an item. If I then, in the handler, do a strongly consistent read to the item, will I be able to see the side-effect of W?


Solution

  • One you understand how DynamoDB operates, the questions will almost answer themselves.

    DynamoDBs architecture is built on a leader - follower model. All writes are written to the leader node for any given partition replica group.

    When you do a strongly consistent read, you will always read from the leader also. This guarantees that you will be returned any data that was successfully written before it.

    1. It depends if another write happened after X but before the read, from any thread. Strongly consistent reads will return the result of all actions that happened before it got there.

    2. Yes, again the read happens after Wx but before Wy so you get the image which is on disk, which is the result of Wx.

    3. Yes, however the Lambda should have the entire result of W which does not necessitate an additional read.