The rules for what a reader may see after a write: strong, eventual and the ones in between.
A consistency model is a promise about what a reader may see after someone has written data, when that data is stored on several copies.
To survive failures and serve users near them, we keep copies (replicas) of data on many machines. But a write cannot reach every copy at the same instant, because the network takes time and some machines are slow or down. So for a short time the copies disagree. A consistency model says which disagreements the user is allowed to notice.
It is a contract between the database and the programmer. A strong model makes the programmer's life easy but costs speed and availability. A weak model gives speed and availability but pushes more work to the programmer, who must handle old or out-of-order data.
| Model | The promise | Cost or catch |
|---|---|---|
| Strong (linearizable) | Each operation seems to happen at one instant, and every read returns the latest completed write | Needs coordination across copies: higher latency, and unavailable on some partitions |
| Sequential | All clients see operations in the same single order, which respects each client's own order | Order is shared, but a read may not show the very latest write in real time |
| Causal | Operations that depend on each other are seen in that order by everyone. Unrelated ones may differ | Needs tracking of dependencies (for example vector clocks) |
| Read-your-writes | After you write, your own reads show it | Other users may still see old data |
| Monotonic reads | Once you have seen a value, you never see an older one | Reads must stick to a fresh enough replica |
| Eventual | If writes stop, all copies finally agree | No promise about when, and reads can be old or out of order meanwhile |
2 + 2 > 3, so the two sets always share a copy (here B) and the read sees the latest value.
1 + 1 is not more than 3. The read can miss the write. Faster, but only eventually consistent.
| Method | How it works | Used by |
|---|---|---|
| Last write wins | The write with the newest timestamp is kept | Cassandra (default), many caches. Can lose a write if clocks differ. |
| Version vectors | Keep both versions when they are concurrent and let the app merge | Dynamo-style stores, Riak |
| CRDTs | Data types built so that merges always work, in any order | Redis CRDB, Riak, collaborative tools |
| Read repair and anti-entropy | Fix stale copies when they are read, or compare copies in the background | Cassandra, DynamoDB-style systems |
A write is confirmed by the leader alone and copied to the others later. A read goes to one replica, so it may be old, but all replicas agree in the end.
A simplified model with fixed delays (no random numbers). The user changes x from 3 to 5 at tick 2. Real systems differ in the details, but the trade is the same: fresher reads cost slower or less available writes.
| Term | Meaning in easy words |
|---|---|
| Replica | One copy of the data on one machine |
| Linearizability | The strongest model: every operation seems to happen at a single instant, in real-time order |
| Sequential consistency | Everyone agrees on one order of operations, but it need not match real time |
| Causal consistency | Operations that depend on each other are seen in the same order by everyone |
| Eventual consistency | If writes stop, all replicas become the same after some time |
| Read-your-writes | A client always sees its own earlier writes |
| Monotonic reads | A client never sees data go back to an older state |
| Stale read | A read that returns an older value than the latest write |
| Quorum | The minimum number of replicas that must answer (usually a majority) |
| Replication lag | How far a replica is behind the leader |
| Conflict resolution | The rule used to choose or merge when two copies changed at once |
| Choice | We gain | We lose |
|---|---|---|
| Strong consistency | Always the latest value, simple code | Higher latency, lower availability under partitions |
| Eventual consistency | Speed, scale and availability | Stale reads, conflicts, extra app logic |
| Read from the leader only | Fresh reads | No read scaling, leader gets busy |
| Read from any replica | Read scaling and low latency | Possible stale reads |
| Quorum (W + R > N) | Fresh reads without one leader | Every call waits for several replicas |
| Last write wins | Simple conflict rule | Can silently drop a concurrent write |