Eventual Consistency
Eventual consistency means that replicated data may temporarily differ, but replicas converge to the same value when updates stop and replication completes. It trades immediate agreement for availability, latency, or scalability in distributed systems.
In a distributed system, the same logical data can exist on multiple replicas. With eventual consistency, a successful write does not necessarily make every replica reflect the new value immediately, so a read routed to another replica can temporarily return an older value.
The system relies on replication to propagate changes. If no new updates continue and the replication process succeeds, the replicas eventually converge. The model therefore provides a convergence guarantee rather than a guarantee that every read immediately observes the newest write.
Eventual consistency is useful when temporary stale reads are acceptable. Common examples include caches, replicated read stores, DNS-like systems, and some distributed databases. The acceptable amount of staleness depends on the application's requirements.
Idempotency is related but different. Idempotency means repeating the same operation produces the same intended result as performing it once; it helps make retries safe when networks or services fail. Eventual consistency describes how replicated state converges, while idempotency describes the behavior of repeated operations.
Key points
- Replicas can temporarily return different values.
- Replicas are expected to converge after updates stop and replication succeeds.
- A successful write does not imply every subsequent read immediately sees it.
- Eventual consistency can reduce coordination costs and improve availability or latency.
- Idempotency makes retries safer but does not itself provide consistency.
Interview questions
What is eventual consistency?
Eventual consistency is a distributed-systems model where replicas may temporarily contain different values. Updates are propagated asynchronously or with some delay. If updates eventually stop and replication succeeds, the replicas converge to the same state. This can provide useful availability and latency characteristics when immediate global agreement is unnecessary.
What can a client observe under eventual consistency?
A client can temporarily read an older value after another operation has updated a different replica. Different clients can also observe different versions during the propagation period. The exact guarantees depend on the database or service because eventual consistency is a broad model rather than one universal implementation. Applications should therefore understand the specific consistency guarantees offered by their storage system.
Why would a system choose eventual consistency instead of strong consistency?
Strong consistency can require coordination between replicas before an operation is considered complete or a read is served. That coordination can add latency and can make availability harder during network partitions. Eventual consistency allows replicas to operate with less immediate coordination and reconcile later. The trade-off is that applications must tolerate temporary stale or divergent data.
How is idempotency related to eventual consistency?
They solve different distributed-systems problems. Eventual consistency describes how replicated state behaves and eventually converges. Idempotency describes whether repeating an operation has the same intended effect as performing it once. Idempotent operations are particularly useful when clients retry requests because of timeouts or uncertain delivery, but idempotency alone does not make replicas strongly or eventually consistent.
How would you design an application around eventual consistency?
First, identify which reads can tolerate stale data and which require stronger guarantees. For operations that can be retried, make commands idempotent using stable request or operation identifiers where appropriate. For user-facing workflows, consider techniques such as read-your-writes routing, version checks, or explicit status states when immediate visibility matters. Finally, monitor replication lag and define application-level behavior for conflicts or prolonged divergence.