Eventual consistency is a consistency model used in distributed systems and databases where:
⚠️ Not all nodes are immediately consistent, but if no new updates are made, all replicas will eventually become consistent over time.
🧠 Real-World Analogy
Imagine you’re updating your profile picture on a global social network. You update it in Russia, but a friend in the US still sees the old picture for a few seconds. After a short delay, they see the new one.
That’s eventual consistency — the system prioritizes availability and performance, with temporary inconsistency allowed.
📚 Key Characteristics
Property | Description |
---|---|
Temporary inconsistency | Reads may return stale data |
High availability | Nodes can serve requests even if out of sync |
No strict ordering | Updates can be applied in different order |
Convergence | Eventually, all replicas apply all updates |
🆚 Compared to Strong Consistency
Feature | Strong Consistency | Eventual Consistency |
---|---|---|
Read after write | Always reflects latest write | Might return stale data |
Latency | Higher | Lower |
Availability | Lower in partition failures | Higher |
Use cases | Banking, critical apps | Social feeds, caching, DNS |
🛠️ Where It’s Used
- Amazon DynamoDB
- Cassandra
- MongoDB (in eventual consistency mode)
- DNS systems
- CDNs (Content Delivery Networks)
🔄 Techniques to Achieve Eventual Consistency
- Background synchronization
- Conflict resolution (last-write-wins, vector clocks, CRDTs)
- Quorum-based writes/reads (e.g., read from
R
, write toW
, whereR + W > N
)
🧰 Example: Amazon Dynamo
- Writes propagate to multiple replicas asynchronously
- A read may hit a stale node, but the system will repair it in the background
✅ Benefits
- High availability
- Better performance
- Scales well in distributed environments
⚠️ Trade-offs
- Data might be inconsistent temporarily
- Requires app developers to handle conflicts or stale reads
🔍 Summary
Term | Meaning |
---|---|
Eventual consistency | All nodes will agree eventually, not immediately |
When to use it | For systems where real-time accuracy isn’t critical |
Benefits | Speed, fault tolerance, scalability |
Drawbacks | Complexity, stale reads |