Sub topic 3
Linearizability: behaving like a single copy
This chapter assumes you know what replication is, that a consistency model is a contract on histories, and that you can read short Python and timeline traces.
The definition
Linearizability is the strongest single-object consistency model. A system is linearizable if every operation appears to take effect at one instant, somewhere between its start and its completion. The system must also behave as if there were one copy of the data.
Two rules follow from this:
- All operations fit into one total order that obeys the object's sequential specification. A read returns the value of the latest write in that order.
- The order respects real time. If operation A completes before operation B starts, A must come before B in the order.
Operations that overlap in time may be ordered either way. The system picks one order, and every client must see results consistent with it.
A history that fails
Here is the history from the topic's running example.
Client A: write(x, 1) starts t=0, completes t=2
Client B: read(x) starts t=3, returns 0
Initial value of x is 0.B's read started after A's write completed. Real-time order therefore puts the write first, and the read must return 1. It returned 0, so the history is not linearizable.
The same history could still be sequentially consistent or eventually consistent. Those models do not require the real-time rule. The next chapter covers sequential consistency.
A history that passes
Now let the read overlap the write.
Client A: write(x, 1) starts t=0, completes t=4
Client B: read(x) starts t=2, returns 0The operations overlap, so the system may place the read before the write. Returning 0 is legal. Returning 1 would also be legal.
The linearization point
Think of each operation as having a hidden linearization point, a single instant inside its time window where it takes effect. A history is linearizable if you can choose one point per operation so that the points form a valid sequential history.
Why it is useful
Linearizability lets you reason about a replicated system as if it were a variable in one process. It is the model you want for:
- Locks and leader election, where two clients must never both believe they hold the lock.
- Unique constraints, such as claiming a username.
- Any check-then-act logic that must see the latest value.
What it costs
A linearizable read must reflect every write that has already completed. Replicas therefore have to coordinate, usually through a leader or a quorum round trip. This adds latency. During a network partition, some replicas cannot be reached, and a linearizable system must refuse requests rather than return stale data. The CAP chapter explains this in detail.
Exercise
Client A's write(x, 5) completes at t=10. Client B starts read(x) at t=12 and returns the previous value 3. Client C starts read(x) at t=8 and returns 3. Which of these reads violates linearizability, and why?
Show answer
Only B's read violates it. B started after the write completed, so real-time order requires it to see 5. C's read started at t=8, before the write completed at t=10, so it overlaps the write. The system may order C's read before the write, and returning 3 is legal.