Is my read always strongly consistent after a conditional putItem operation in dynamodb?

0

Assumption: Single region table

  1. How does a conditional write putItem operation verifies the latest data? Does it do a Strongly Consistent read or considers only the response of the coordinator node
  2. Is my conditional write putItem operation waits for write operation completion across all replicas before returning success
  3. Will my eventually consistent read get guaranteed latest data if my write on the same key was conditional write putItem operation

Summary Question: Given a service where only type of write operation performed is conditional write putItem operation, will all my default read operations (consistent read parameter set to false by default) be strongly consistent i.e will all my replicas have latest data post a conditional write putItem operation in dynamodb

  • please accept the answer if it was useful

asked 4 months ago651 views
2 Answers
3

The accepted answer to this question is wrong.

When a write happens to DynamoDB (conditional or otherwise), it is accepted by a leader node, which asynchronously replicates to at least 2 followers. A success response (200) is only returned when one of the followers acknowledges the write. This means that 2/3 of the replicas hold the latest data. However, an eventually consistent read can still be directed to the third replica, which has not yet caught up, returning stale data.

Writes to DynamoDB are strongly serialized by a leader node, along with strongly consistent reads. Writes never perform read operations, so you never need to worry about the consistency of a write (conditional or otherwise).

TLDR; An eventually consistent read can always return stale data. If you need the latest data, perform a strongly consistent read.

profile pictureAWS
EXPERT
answered 3 months ago
  • What happens when my leader node goes down given DynamoDB responded with success when 1 follower returned success and my next follower doesn't have the updates yet or failed to get updated

    1. Will my writes be affected (availability go down) until all replicas/followers come in sync?
    2. If no to 1 and If a new leader will be elected and writes don't perform reads, how do we ensure the new leader has the latest data? The new leader could be the one who doesn't have latest data yet and my condition is evaluated incorrectly?
    3. If no to 1 and 2, If the request is simply redirected to next node in preference list, it is possible that it doesn't have latest data and my condition is evaluated incorrectly?
-2
Accepted Answer

DynamoDB ensures the condition check during a putItem operation is based on the latest data in the table. This means the condition is evaluated using a strongly consistent read to ensure that the condition is checked against the most recent data before the write is applied.

When a conditional putItem operation is performed, DynamoDB ensures that the write is committed across all replicas before it returns success. This guarantees that the write is durable and replicated.

Conditional writes check their conditions against the most recently updated version of the item. Note that if the item did not previously exist or if the most recent successful operation against that item was a delete, then the conditional write will find no previous item.

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.ConditionalUpdate

Eventually consistent reads do not guarantee the latest data immediately after a write. To get strong consistency in reads, you need to use strongly consistent reads explicitly.

profile picture
EXPERT
answered 4 months ago
profile picture
EXPERT
reviewed 3 months ago
  • When a conditional putItem operation is performed, DynamoDB ensures that the write is committed across all replicas before it returns success. This guarantees that the write is durable and replicated.

    If the write is committed across all replicas before it returns success, eventually consistent read i.e read going to any replica should give latest data. Will that not be the case?

  • yes, if your Read happens after the write (not in parallel)

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions