0
0
DynamoDBquery~10 mins

Consistent vs eventually consistent reads in DynamoDB - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Consistent vs eventually consistent reads
Write data to DynamoDB
Data stored in primary storage
Eventually Consistent Read
After replication delay
Replicas updated with latest data
Strongly Consistent Read
Data is written once, then reads can be either eventually consistent (may be stale) or strongly consistent (always latest).
Execution Sample
DynamoDB
PutItem: {id:1, name:'Alice'}
ReadItem (eventually consistent)
ReadItem (strongly consistent)
Write a record, then read it with two different consistency settings.
Execution Table
StepActionData SourceData ReturnedNotes
1PutItem {id:1, name:'Alice'}Primary StorageData storedData written to main storage
2ReadItem (eventually consistent)ReplicaOld or empty dataReplica might not be updated yet
3Replication delayReplicas updatingData propagatingReplicas get latest data
4ReadItem (eventually consistent)Replica{id:1, name:'Alice'}Replica now has latest data
5ReadItem (strongly consistent)Primary Storage{id:1, name:'Alice'}Always returns latest data
💡 Reads stop after returning data; eventually consistent reads may return stale data until replicas update.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5
Primary Storage Dataempty{id:1, name:'Alice'}{id:1, name:'Alice'}{id:1, name:'Alice'}{id:1, name:'Alice'}{id:1, name:'Alice'}
Replica Dataemptyemptyempty or old dataupdating{id:1, name:'Alice'}{id:1, name:'Alice'}
Key Moments - 2 Insights
Why does an eventually consistent read sometimes return old data?
Because replicas may not have received the latest update yet, as shown in step 2 of the execution_table where the replica data is still empty or old.
How does a strongly consistent read ensure the latest data?
It reads directly from the primary storage which always has the latest data, as shown in step 5 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what data does the eventually consistent read return at step 2?
AThe latest data {id:1, name:'Alice'}
BAn error
COld or empty data
DData from primary storage
💡 Hint
Check the 'Data Returned' column at step 2 in the execution_table.
At which step does the replica get updated with the latest data?
AStep 3
BStep 1
CStep 5
DStep 2
💡 Hint
Look at the 'Notes' column describing replication delay in the execution_table.
If you want to always read the latest data, which read type should you use?
AEventually consistent read
BStrongly consistent read
CAny read type works the same
DRead from replicas only
💡 Hint
Refer to the 'Data Source' and 'Data Returned' columns at step 5 in the execution_table.
Concept Snapshot
Consistent vs Eventually Consistent Reads in DynamoDB:
- Write data once to primary storage.
- Eventually consistent reads read from replicas and may return stale data.
- Strongly consistent reads read from primary storage and always return latest data.
- Eventually consistent reads are faster but may lag behind.
- Use strongly consistent reads when you need the freshest data.
Full Transcript
When you write data to DynamoDB, it is stored in the primary storage. Reads can be done in two ways: eventually consistent or strongly consistent. Eventually consistent reads get data from replicas which might not be updated immediately, so they can return old data right after a write. Strongly consistent reads always get data from the primary storage, ensuring the latest data is returned. This means eventually consistent reads are faster but may be stale, while strongly consistent reads are slower but always fresh. The execution table shows the write, the first read returning possibly old data, the replication delay, and then reads returning the latest data.