Home > Enterprise >  Are DynamoDB Condition Writes Transactional Writes?
Are DynamoDB Condition Writes Transactional Writes?

Time:10-14

I'm having trouble wrapping my head around the dichotomy of DDB providing Condition Writes but also being eventually consistent. These two truths seem to be at odds with each other.

In the classic scenario, user Bob updates key A and sets the value to "FOO". User Alice reads from a node that hasn't received the update yet, and so it gets the original value "BAR" for the same key.

eventual consistency

If Bob and Alice write to different nodes on the cluster without condition checks, it's possible to have a conflict where Alice and Bob wrote to the same key concurrently and DDB does not know which update should be the latest. This conflict has to be resolved by the client on next read.

But what about when condition write are used?

User Bob sends their update for A as "FOO" if the existing value for A is "BAR". User Alice sends their update for A as "BAZ" if the existing value for A is "BAR".

cond write

Locally each node can check to see if their node has the original "BAR" value and go through with the update. But the only way to know the true state of A across the cluster is to make a strongly consistent read across the cluster first. This strongly consistent read must be blocking for either Alice or Bob, or they could both make a strongly consistent read at the same time.

So here is where I'm getting confused about the nature of DDBs condition writes. It seems to me that either:

  1. Condition writes are only evaluated locally. Merge conflicts can still occur.
  2. Condition writes are evaluated cross cluster.

If it is #2, the only way I see that working is if:

  1. A lock is created for the key.
  2. A strongly consistent read is made.

Let's say it's #2. Now where does this leave Bob's update? The update was made to node 2 and sent to node 1 and we have a majority quorum. But to make those updates available to Alice when they do their own conditional write, those updates need to be flushed from WAL. So in a conditional write are the updates always flushed? Are writes always flushed in general?

There have been other questions like this here on SO but the answers were a repeat of, or a link to, the AWS documentation about this. The AWS documentation doesn't really explain this (or i missed it).

CodePudding user response:

DynamoDB conditional writes are "transactional" writes but how they're done is not public information & is perhaps proprietary intellectual property.

DynamoDB developers are the only ones with this information.


Your issue is that you're looking at this from a node perspective - I have gone through enter image description here


Condition writes are probably evaluated cross-cluster & a strongly consistent read is probably made but Amazon has not made this information public.

  • Related