Advanced Topic 45 of 51 Databases
Eventual Consistency
Replicas converge to the same state given time.
How it works
Eventual consistency is a guarantee that if no new updates are made, all replicas of a data item will converge to the same value after some time. Updates propagate asynchronously, so a read right after a write may return old data from a replica. Techniques that help include read repair, anti-entropy with Merkle trees, vector clocks, last-write-wins and conflict-free replicated data types, plus quorum reads and writes to tune freshness.
Step-by-step walkthrough
- The client writes x = 2 to replica 1.
- A read from replica 2 still returns the old x = 1.
- Replica 1 propagates the update.
- After a short time replica 2 has x = 2.
- Replicas converge when no new writes arrive.
Where it is used
Shopping carts, social feeds, DNS, caches, collaborative editing and globally replicated stores favor eventual consistency for availability and low latency.
Common pitfall
Applications may see stale or out-of-order data and conflicting concurrent writes that must be merged correctly. Last-write-wins can silently lose updates and depends on clocks. Design the user experience for temporary inconsistency, use idempotent operations and apply stronger consistency to critical operations like payments or inventory counts.
Where it fits in the course
Eventual Consistency is topic 45 of 51 in Databases, rated Advanced. It follows CAP Theorem. The next topic is Data Warehousing.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Databases quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Databases quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Eventual Consistency?
Where do people use Eventual Consistency?
What is the most common mistake with Eventual Consistency?
What should I learn before this topic?
How can I practice it?
Is Eventual Consistency hard to learn?
How long does it take to learn Eventual Consistency?
Which topics are related to Eventual Consistency?
What should I study after Eventual Consistency?
Related topics
- CAP Theorem (Databases)
- Data Warehousing (Databases)
- Graph Databases (Databases)
- OLTP vs OLAP (Databases)
- Consistency Models (Distributed Systems & Cloud)
- Memory Consistency Models (Computer Architecture & Logic)