FAILURE MODELS & TIMEOUTS

You cannot tell a dead node from a slow one

L114 MINDISTRIBUTED SYSTEMS
PREDICT

P heartbeats every 100 ms. S declares P dead after 300 ms of silence and promotes itself. P then freezes in a 500 ms GC pause. What happens when P wakes up?

A node can fail in several ways. Crash-stop: it halts and never returns. Crash-recovery: it halts and comes back with its disk but not its memory. Partition: it runs fine but you cannot reach it. Slow: it runs, but a GC pause, a swapped-out page or a saturated link delays it for seconds. From the outside these are the same thing: silence.

A heartbeat detector measures silence and compares it to a timeout. Pick 300 ms and a 500 ms pause looks like a death. Pick 5 s and a real crash costs 5 s of outage. The timeout is a guess about the network, and the network does not read your config.

▶ SIMULATION
P (PRIMARY)
state: RUNNING
believes: I am primary · epoch 1
writes accepted: 0
heartbeat every 100 ms · 0 delivered
FAILURE DETECTOR (runs on S)
t = 0 ms
silence: 0 ms / threshold 300 ms (fixed)
P is: alive · suspicion 0.00 of 1.00
gaps seen: — ms
S (STANDBY)
role: STANDBY · epoch 1
writes accepted: 0
waiting for the detector
last write round—
✓ a node declared dead is actually dead✓ at most one node gets its writes accepted
SCHEDULE
01[CLOCK]+200 ms (P heartbeats every 100 ms)
02[P]P: minor GC pause, 250 ms (one slow heartbeat)
03[CLOCK]+200 ms (P heartbeats every 100 ms)
04[CLOCK]+200 ms (P heartbeats every 100 ms)
05[P]P: kernel panic — crash-stop, no more heartbeats ever
06[CLOCK]+200 ms (P heartbeats every 100 ms)
07[CLOCK]+200 ms (P heartbeats every 100 ms)
08[CLIENTS]clients: send a write to every node that calls itself primary
09[AUDIT]audit: how many nodes accepted writes?
Start of crash-stop scenario. 9 steps.
// Fixed timeout: silence > 300 ms means dead. A GC pause is silence too.
if (now - lastHeartbeatAt > 300) {
  declareDead(primary);
  promote(standby);        // the "dead" primary wakes up and keeps serving
}

Watch the invariant strip in SLOW NODE, FIXED TIMEOUT: it turns red at t = 850 ms, when the detector declares P dead while P is alive, and again when both nodes accept a write. In FIX: ADAPTIVE SUSPICION the same pause happens and the strip stays green, because the threshold is 3 times the largest gap seen so far. That only works because the warm-up already had a 250 ms pause, so the threshold was 750 ms. With a clean 100 ms history it would be 300 ms and this pause would fire too: an adaptive detector tolerates pauses within a few times what it has already seen, not a first-ever long one. It also has a cost. The 550 ms gap raises the threshold to 1650 ms, so the real crash is caught 1650 ms later. The max-gap rule is a simplification; real phi accrual uses the mean and variance of a sliding window of recent gaps, so one old pause does not loosen it forever. So the detector can still be wrong. FENCE ONLY shows the other half of the fix: the detector is wrong and it does not matter.

TUNE IT NOT YET

P freezes for 500 ms, recovers, then really crashes. Find the smallest TIMEOUT that never declares the frozen P dead and still detects the real crash within 1000 ms. One step lower and the pause becomes a false positive. Watch the silence counter: the pause starts some time after the last heartbeat.

GOAL: no false positive, crash detected within 1000 ms, and TIMEOUT - 50 would have fired while P was alive

FIX IT NOT YET

Implement suspect(lastHeartbeatAt, now, history): return true when the node should be suspected dead. The grader runs two clusters, a fast one (heartbeats about every 100 ms) and a slow one (about every 400 ms). Each has an earlier minor pause in its history, one long GC pause that must not fire, and one real crash that must be caught within the bound. No fixed number passes both.

Mental model:

A failure detector is a guess dressed up as a fact. Silence is the only input it has, and silence has many causes. So treat its output as suspicion, make the threshold track what the network actually does rather than a number in a config file, and never let a suspicion alone change who is allowed to write. A fence (an epoch that storage checks) is what turns a wrong guess from a data corruption into a rejected request.

IN PRODUCTION

Kubernetes liveness probes and node-not-ready timeouts, Patroni and Orchestrator MySQL failover, ZooKeeper and etcd session timeouts, Cassandra's phi accrual detector, any load balancer health check. The symptom: a failover or pod restart that fires during a GC pause, a deploy, or a network blip, and sometimes a split brain behind it.

IN INTERVIEWS

“How do you detect that a node is down?” and “What goes wrong if you get it wrong?” Say that you cannot distinguish crashed from slow from partitioned, name the false-positive versus detection-latency trade-off, mention adaptive detectors, and finish with fencing: the system must stay correct even when the detector is wrong.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: Replication Lag →