LESSON 01 · Linearizability

Make replicas look like one copy

Linearizability makes a replicated store behave like a single copy, so reads never go back in time, and you pay for it in latency and availability.

SYSTEM VIEW

The agreement path

Diagram view
Time—
Reads must see—
Stale reads—

Watch one write and two reads of seat 14 on a millisecond clock, then replay the stale read with a check that keeps it current.

  1. Seat 14 is free on both replicas. At t=10 Client A starts writing “sold”, and the leader applies it at t=15. Until A hears back, the write is in progress: it takes effect at one instant somewhere between its start and its finish.

    A’s write
    from t=10
    Leader applies it
    t=15

    What changed

    • A’s write starts at t=10
    • Leader: seat 14 sold
  2. Client B reads from t=15 to t=20, while A’s write is still in progress, so either answer would be acceptable. It returns “sold”. The write has now visibly taken effect, so every read that starts after t=20 must return “sold” too.

    B’s read
    t=15 to 20
    Reads after t=20
    must see sold

    What changed

    • B’s read returns sold
    • Later reads must see sold
  3. The leader’s acknowledgment reaches A at t=30, and A’s write is complete: any read that starts now must return “sold”, whichever replica it asks. But the follower copies writes later. It still holds “free”, and catches up only at t=90.

    A’s write
    t=10 to 30
    Follower
    free until t=90

    What changed

    • A’s write acknowledged
    • Follower behind
  4. At t=40, after the acknowledgment and after B saw “sold” at t=20, Client C reads from the follower and gets “free”. The read went back in time, so the guarantee is broken, and the follower catching up 50 ms later, at t=90, doesn’t undo it.

    B’s read, t=20
    sold
    C’s read, t=40
    free

    What changed

    • C’s read returns free
    • 1 stale read
  5. Replay it with C’s read sent to the leader. Before answering, the leader checks with a majority that it still leads: the follower’s yes makes 2 of 2, so no newer leader can hold writes it lacks. C gets “sold” at t=60: 20 ms, against the stale read’s 10.

    Read from the follower
    10 ms, stale
    Confirmed read
    20 ms

    What changed

    • C reads from the leader
    • One extra round trip
    • C’s read returns sold
  6. Replay it with the follower cut off at t=35. The leader’s check gets no answer, so it can’t confirm a majority and refuses C’s read with a “no” rather than risk a stale one. Spend this where stale answers do harm: locks, leader election, unique usernames. A like counter rarely needs it.

    Worth it for
    locks, usernames
    Rarely for
    like counters

    What changed

    • Follower cut off
    • C’s read refused

Space plays · ← → step · Home resets

THE IDEA

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.

DECISION POINT

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?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

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.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
ApplyQUESTION 01

A write is acknowledged at t=30. Another client’s read starts at t=40. What must a linearizable store return?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.