Topic 127 / Advanced
Failure detection: heartbeats and gossip
Chapter 8.1 · The Nature of Distribution
What and why
Because a distributed system can't know a remote node's true state (→ 126), it needs a policy for deciding, imperfectly, whether a node is up — so the rest of the system can route around it. Failure detection converts an ambiguous signal (a missing reply) into an operational decision using heartbeats (direct periodic pings with a timeout) or gossip (indirect, epidemic dissemination of what each node believes about every other node's state). Builds on: → 126 (partial failures and network partitions).
Diagram
Heartbeat (direct): Gossip (epidemic):
node ──ping (every T)──► monitor each round, a node picks a few
node ◄──ack──────────── monitor random peers and exchanges its
3 missed beats ⇒ "suspected down" membership view with them —
updates spread node-to-node
How it works
- Heartbeat: each node sends a small "I'm alive" message to a monitor (or its peers) every fixed interval; missing N consecutive heartbeats flips that node's status to "suspected down."
- The timeout is a tuning trade-off: too short produces false positives under a slow GC pause or a loaded link; too long delays detecting a real failure — no single value eliminates both risks.
- A heartbeat monitored centrally by one node creates a new single point of failure and a hot path; gossip avoids this by having every node periodically exchange its membership view with a few random peers instead.
- Gossip: each round, a node shares what it currently believes about every other node's liveness and version with a few random peers; information spreads epidemically, typically reaching the whole cluster in a number of rounds that grows slowly (not linearly) with cluster size — no central coordinator, no single point of failure, but updates propagate with a delay (eventually consistent, not instant).
- Either mechanism only ever produces a suspicion, never a certified fact; a node marked "down" may still be alive and merely partitioned, which is exactly why fencing (→ 133, → 137) matters for anything that acts on that suspicion by taking over a role.
Practical example
(illustrative). A heartbeat interval of 1 second with a 3-missed- beat timeout detects a genuinely crashed node in about 3 seconds, but it also flags a node that merely pauses for 3.5 seconds under load as "down," even though it recovers a moment later — a false positive the cluster must tolerate gracefully rather than treat as final.
When to use it
- Use when: heartbeats for small, bounded groups where a direct check is cheap (a leader and its followers); gossip for large, dynamic memberships a central checker doesn't scale to (leaderless store membership, Capstone).
- Avoid when: treating "suspected down" as "confirmed down" for any action that isn't safely reversible.
- Failure scenarios: a node slowed by GC or disk I/O gets evicted, rejoins, and now conflicts with whatever took over its role (→ 137 fencing tokens); a gossip round interval set too long leaves the cluster's view of membership stale exactly when a failure matters most.
- Simpler alternative: for a handful of nodes, a load balancer's own health check (→ 92) is often enough — reserve gossip for memberships too large or dynamic for any one node to check directly.
Practice
(Mechanism kind — build a tiny version; 20–30 min, no lab services, any language). Simulate 5 processes exchanging heartbeats on one machine with artificial random delays before each reply. Flag a process "suspected down" after 3 missed beats; introduce one process that pauses longer than the timeout but doesn't crash, and confirm it gets a false-positive flag. Done when you can show the false positive happening and state which timeout value would have avoided it, and what new risk that larger value introduces.
Key takeaway
Failure detection never produces certainty, only a timing-based suspicion; heartbeats suit small groups, gossip scales to large, dynamic ones at the cost of detection delay. Done when you can: compute the detection delay from a stated interval and threshold, and name one false-positive scenario each mechanism allows. Used next in → 131, 133.
References
Kleppmann and Riccomini, Designing Data-Intensive Applications — see
references.md.