FAILURE MODELS & TIMEOUTS
You cannot tell a dead node from a slow one
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.
// 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
}// 1. Suspicion that scales with what the network actually does:
const threshold = 3 * Math.max(...recentHeartbeatGaps);
if (now - lastHeartbeatAt >= threshold) suspect(primary);
// 2. Never act on suspicion alone: promotion takes a new epoch,
// storage rejects writes carrying an older one.
const epoch = store.bumpEpoch(); // fencing token
promote(standby, epoch);
// old primary: store.write(v, epoch=1) -> rejected (1 < 2) 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.
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
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.
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.
“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.
USED IN
Chapters that build on this lesson.
- Failover, split brain and fencingDatabases
- Chaos and resilience testingSRE, Platform and DevOps
- Disaster recovery and business continuitySRE, Platform and DevOps
- Production readiness reviewsSRE, Platform and DevOps