How it works
Replication gives you several copies of a value, and they do not change at the same instant. A client can finish a write on the leader, then read an old value from a lagging follower. Linearizability removes that gap: the system behaves as if there were one copy, and each operation takes effect at a single instant between its start and its finish.
Follow a timeline in milliseconds, with seat 14 free. Client A writes “sold” from t=10 to t=30. Client B reads from t=15 to t=20. That read overlaps the write, so either answer is acceptable. If it returned “sold”, the write has taken effect, and every read starting after t=20 must also return “sold”. Client C reads at t=40, after the acknowledgment, so it must see “sold”. A follower returning “free” at t=40 breaks the guarantee, even if it catches up 50 ms later.
This differs from serializable isolation, which makes multi-step transactions match some serial order that need not follow real time. Linearizability is about recency on a single object. Having both is called strict serializability.
To deliver it, a read must confirm it is not stale, for example by having the leader check with a majority that it still leads, which usually adds a round trip. A node that cannot reach enough peers has to stop answering. Spend this where a stale answer causes harm, such as locks, leader election, and unique usernames. A like counter rarely needs it.
A profile service replicates asynchronously to followers. After changing their display name, users sometimes see the old one. You could make all reads linearizable at an extra 10 ms per read, or route a user’s own reads to the leader for 5 seconds after they write. Which do you pick?
Route the writer’s reads to the leader, which approximates the guarantee known as read-your-writes. The person who notices is the one who made the change, and another viewer seeing an older name for a moment causes no harm. This is not linearizable, since a different user can still read the old name after the write is acknowledged. Keep linearizable operations for cases where stale data does damage, such as a lock or a uniqueness check.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Linearizable means one apparent copy: once a read returns a new value, later reads do too.
- A read overlapping a write may return either value, until some read has returned the new one.
- It costs extra round trips, and refusing requests when a majority is out of reach.