Try
↑ ↓ move↵ openesc close
In this lesson · topic 4 of 7
  1. 1. One copy is not enough
  2. 2. Three ways to say yes
  3. 3. Slow the network and kill the leader
  4. 4. When a leader crash loses acknowledged writes
  5. 5. What the replication log actually contains
  6. 6. How a follower falls hours behind
  7. 7. Check the failover and lag cases

Topic 4

When a leader crash loses acknowledged writes

6 min read

Every figure here is simulator output with fixed seeds, pinned by a test. Hover one to see how it was produced.

The three rules side by side

Three followers, a mean one-way delay of 20 ms, 40 writes a second, reads sent to a random follower:

Rule Mean write latency (ms) Reads that were stale
Asynchronous 1.0measured 55%measured
Semi-synchronous 34.3measured 4%measured
Synchronous 57.7measured 0%measured

The stale share under asynchronous replication tracks how often at least one write is in flight at a random moment. With writes arriving at random, that chance climbs quickly as the write rate times the delay grows. Synchronous reads are never stale here, because a write is not acknowledged until every follower has it. Semi-synchronous sits in between. A stale read there needs the read to pick a follower other than the one that acknowledged, at a moment when that follower had not caught up.

The network is on the path

Raise the one-way delay to 150 ms and asynchronous write latency stays at 1.0measured ms. Synchronous write latency becomes 556measured ms. That is more than the two trips of 150 ms the textbook arithmetic gives, because followers apply entries in order. A slow message holds up every entry behind it, so the delay a write sees is the worst of several trips. Variable delay hurts more than a steady one with the same mean. Meanwhile 100%measured of reads under asynchronous replication are stale, because there are always several writes in flight.

What a crash loses

Kill the leader after 40 simulated seconds with 100 writes a second and 40 ms of delay. The promoted follower is the one furthest ahead. The average number of acknowledged writes that vanished:

Rule Acknowledged writes lost
Asynchronous 4.0measured
Semi-synchronous 0.0measured
Synchronous 0.0measured

The asynchronous loss scales with how much was in flight. With a delay of 5 ms it was 0.4measured, and with 150 ms it was 23.1measured. Each lost write was something a client had been told succeeded.

What the session guarantees cost

Asynchronous replication, 80 ms of delay, 60 writes a second. Share of reads where a client did not see its own acknowledged write:

Where reads go Own write missing Went back in time Reads served by the leader
Any follower, at random 41.6%measured 12.1%measured none
One fixed follower per client 41.5%measured 0.0%measured none
Follower, leader if behind my last write 0.0%measured not promised 42%measured
Follower, leader if behind anything I have seen 0.0%measured 0.0%measured 61%measured

Two things stand out. Pinning a client to one follower fixes monotonic reads and does nothing for read-your-writes. And the routing fix works, but with this much lag it sends a large share of reads back to the leader, which is the load the followers were meant to remove. Even with the strongest session setting, 38%measured of reads are still stale in the global sense, down from 99%measured with random followers.

What the model leaves out

  • Failover here is instant. Real systems must detect the failure first, which takes seconds and can be wrong. Two nodes both believing they are leader is a separate and worse problem, covered where consensus is.
  • The old leader’s unreplicated writes are discarded when it rejoins. Real systems have to decide what to do with them, and some surface them for a human to resolve.
  • There is one value and a total order. Real logs carry many keys, and transactions that touch several.
  • Followers never crash or fall far behind, and the network never partitions.
  • Write latency is measured at the leader. A client also pays its own trip to the leader.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms