Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
Eventual consistency explained: why replicas briefly disagree, the anomalies users see, conflict resolution with CRDTs, and when it is the right choice.
Quick answer: Eventual consistency is a guarantee that if no new updates are made to a piece of data, all copies of it will eventually hold the same value. In the meantime, different replicas may return different answers. Systems accept this because it lets them reply quickly and stay available during network failures, without waiting for every replica to agree. It is the right trade when briefly stale data is harmless, such as like counts, feeds and product catalogues, and the wrong trade when a stale answer causes real damage, such as account balances or the last item in stock.
To survive failures and serve users around the world, data is copied to several machines. See how database replication works. A write lands on one replica first and then spreads to the others.
There are two ways to handle that gap:
This is the consistency-versus-availability choice from the CAP theorem, and the consistency-versus-latency choice that applies even when nothing is broken.
The term was popularised by Amazon's Werner Vogels in Eventually Consistent, describing the design of Amazon's large-scale storage systems.
None of these feel broken, because the delay is short and the stakes are low.
The definition is weaker than it sounds. It does not say:
Consistency is a spectrum, not a switch. The Jepsen consistency models page maps it out. Several intermediate guarantees remove the most irritating anomalies at modest cost:
| Guarantee | What it promises | Typical implementation |
|---|---|---|
| Read-your-writes | You always see your own updates | Read from the leader after writing, or track the version you wrote |
| Monotonic reads | You never see data go backwards | Pin each user to one replica |
| Causal consistency | Related events appear in order | Track dependencies between writes |
| Bounded staleness | Data is at most N seconds old | Monitor lag; exclude slow replicas |
Many "eventually consistent" databases let you ask for these, or for strong consistency, on a per-request basis.
In Dynamo-style databases such as Cassandra, each piece of data lives on N replicas. You choose how many must acknowledge a write (W) and how many must answer a read (R).
For N = 3: W = 1 and R = 1 is fastest and weakest; W = 2 and R = 2 gives strong reads while tolerating one node down.
If two replicas accept different writes to the same item, something must decide the outcome when they sync.
Last write wins. Keep the write with the newest timestamp. It is simple and common, and it silently throws away data. It also depends on machine clocks agreeing, which they do not; see why clocks can't be trusted.
Version vectors. Track which replica has seen which updates, so the system can tell "A is newer than B" from "A and B were made concurrently". Concurrent versions are both kept.
Application-level merge. Hand both versions to the application. The classic example from Amazon's Dynamo paper is the shopping cart: merge the two carts by taking the union of their items. Nothing added is lost, though a deleted item can occasionally reappear.
CRDTs. Conflict-free replicated data types are data structures designed so that concurrent updates always merge to the same result, in any order. Examples include counters, sets and text sequences. They power collaborative editors and local-first apps that sync after working offline.
Ask one question: what is the worst outcome if a user acts on stale or conflicting data?
| Usually fine | Usually not |
|---|---|
| Like, view and follower counts | Account balances and payments |
| Social feeds and timelines | Stock of scarce items |
| Product descriptions and reviews | Seat and room bookings |
| Search indexes | Unique usernames |
| Analytics and metrics | Permission changes and revocations |
| Caches | Locks and leader election |
Often the answer depends on the business. Overselling one item in ten thousand and apologising may cost less than making every purchase slower. A single product commonly mixes both models: a strongly consistent database for orders and payments, eventually consistent stores for everything around them. See SQL vs NoSQL.
With strong consistency, every read reflects the latest completed write. With eventual consistency, reads may be stale for a while, but all replicas converge once updates stop.
Typically milliseconds to a second. It can be longer during heavy load, failures or network partitions.
No. It is a deliberate trade for speed and availability, and it suits data where brief staleness is harmless.
A data type built so that replicas can be updated independently and always merge to the same result without conflicts.
Eventual consistency means accepting that copies of data will briefly disagree in exchange for a faster, more available system. That is fine for a great deal of data and unacceptable for some. Decide case by case, add guarantees such as read-your-writes where users would notice, and choose a conflict strategy deliberately, because the default one often loses data.