Gossip & Failure Detection: How Large Clusters Know Who Is Alive


System Design Phase 10: Coordination & Distributed Transactions
Advanced Lesson 59 of 86 16 min read Updated Nov 30, 2026

A 600-node cache cluster uses a simple rule: every node pings a central monitor every second, and any node silent for 3 seconds is removed from the routing table. One afternoon a top-of-rack switch starts dropping 5% of packets. Nothing is down. But at 5% loss, the chance that three consecutive pings from the same node are all lost is 0.05 cubed, about 1 in 8,000, and with 40 nodes behind that switch sending a ping every second, some node hits a three-loss streak roughly every 3 minutes.

Each false removal moves that node’s keys to other nodes, which miss in cache and hammer the database. The monitor itself, sitting behind a different switch, starts timing out on half its own traffic. By the time someone looks, the routing table has churned 200 times in an hour and the database is at 95% CPU.

Deciding whether a remote machine is alive sounds trivial. It is impossible to do perfectly: a slow node and a dead node look identical from outside. This article covers how failure detectors trade speed for accuracy, how gossip spreads membership through thousands of nodes without a central monitor, and why the failures that hurt most are the ones where a node is half alive.

What it is

A failure detector is a component that gives each node an opinion about which other nodes are up. It cannot be perfect in an asynchronous network, so it is judged on two axes:

  • Completeness: a crashed node is eventually suspected by every correct node.
  • Accuracy: a healthy node is not suspected, or not often.

The faster you want to detect a real crash, the more often you will falsely suspect a slow one. Every design in this article is a way to move along that curve or to get a better curve.

Gossip (also called epidemic dissemination) is how the opinion spreads. Instead of every node reporting to a monitor, each node periodically exchanges state with a few random peers, who pass it on. Information reaches all N nodes in a number of rounds that grows with log N, with no single point of failure and constant load per node. This is the backbone of membership in Apache Cassandra, ScyllaDB, HashiCorp Consul and Serf, and many service meshes and caches. If you want the background on partial failure and why timeouts are guesses, start with the distributed systems primer.

How it works

Heartbeats and the timeout trade-off

The simplest detector: node A sends a heartbeat every interval T, and B suspects A if no heartbeat arrives for timeout D. Expected detection time for a real crash is about D. The false positive rate depends on how often normal heartbeats are delayed beyond D by GC pauses, packet loss or queueing.

Phi accrual failure detector

Hayashibara, Défago, Yared and Katayama (2004) proposed a detector that outputs a suspicion level instead of a yes or no. Each node keeps a sliding window of recent heartbeat inter-arrival times and models their distribution. When a heartbeat is late by t seconds since the last one, it computes:

phi(t) = -log10( P_later(t) )
P_later(t) = probability that a heartbeat arrives more than t after the previous one,
             according to the observed distribution

So phi = 1 means “there is a 10% chance a healthy node would be this late”, phi = 2 means 1%, phi = 8 means one in a hundred million. Applications pick a threshold; crossing it means suspect.

The win is adaptation. On a jittery network, the observed inter-arrival distribution is wide, so the same silence produces a lower phi and the detector waits longer automatically. On a tight LAN, it convicts faster.

Apache Cassandra uses a phi accrual detector with phi_convict_threshold defaulting to 8, and suggests raising it (for example to 10 or 12) on clouds with noisy networks. Akka and its Apache-licensed fork Pekko use phi accrual for cluster membership, with an acceptable-heartbeat-pause setting that adds headroom for GC pauses.

SWIM: probe randomly, ask for help, suspect before declaring

All-to-all heartbeats cost O(N squared) messages per interval: 1,000 nodes means a million messages a second. SWIM (Das, Gupta and Motivala, 2002) keeps per-node load constant. Every protocol period (say 1 s), each node:

  1. Picks one random member and sends a ping.
  2. If no ack arrives within a short timeout, it asks k other random members to ping-req the target on its behalf. They ping it and relay any ack.
  3. If still nothing, it marks the target suspect rather than dead, and spreads that.
  4. The suspect has a suspicion timeout to refute. It does so by gossiping an “alive” message with a higher incarnation number, a counter only that node may increment. Higher incarnation overrides suspicion.
  5. If the timeout passes with no refutation, the target is declared dead (confirmed) and removed.
sequenceDiagram
participant A as Node A
participant B as Node B (target)
participant C as Node C
participant D as Node D
A->>B: ping
Note over A,B: no ack within timeout (lost or slow)
A->>C: ping-req B
A->>D: ping-req B
C->>B: ping
D->>B: ping
B-->>C: ack
C-->>A: ack relayed for B
Note over A: B is alive, a direct path problem only
Note over A: if no relayed ack, mark B suspect, gossip it, start suspicion timer

Indirect probes separate “B is dead” from “the path from A to B is bad”, which removes many false positives from one flaky link. The suspicion phase gives a slow node a chance to speak up. And instead of broadcasting membership changes, SWIM piggybacks them on the pings and acks it is already sending, which is infection-style dissemination: no extra messages.

Each member sends a constant number of messages per period regardless of N, and the expected time until some member first probes a crashed node is about e / (e - 1), roughly 1.58 protocol periods, independent of cluster size.

Lifeguard: when the detector itself is slow

HashiCorp found that many false positives in production came from the detecting node being unhealthy: a CPU-starved member that cannot process acks in time accuses healthy peers. Their 2017 Lifeguard extensions to SWIM, implemented in the memberlist Go library used by Consul, Serf and Nomad, add:

  • Local health awareness. Each node tracks evidence of its own trouble (missed acks, having to refute suspicion about itself) as a local health score, and stretches its own probe timeouts when that score is bad.
  • Dynamic suspicion timeouts. The suspicion timeout starts long and shrinks as more independent members confirm the suspicion, so a real failure is confirmed quickly when many agree and a single confused accuser cannot evict a node.
  • Buddy system. A node that suspects a peer tells that peer directly in its next ping, so the peer can refute sooner.

In memberlist the base suspicion timeout also scales with log of cluster size, because a suspicion message needs more rounds to reach everyone in a bigger cluster.

Gossip dissemination math

Push gossip: every round, each node that knows an update sends it to f random peers. Early on, almost every message reaches someone new, so the informed set multiplies by about (1 + f) per round. Near the end, most messages hit nodes that already know, and the last few stragglers take extra rounds.

xychart-beta
title "Informed nodes per round (N = 1000, fanout 3, approximate)"
x-axis "Round" [0, 1, 2, 3, 4, 5, 6, 7, 8]
y-axis "Nodes informed" 0 --> 1000
line [1, 4, 16, 63, 230, 600, 930, 997, 1000]

Anti-entropy gossip

Pushing new rumours is fast but can miss nodes, and a node that was offline misses rumours entirely. Anti-entropy gossip has each node periodically pick a random peer and reconcile its full state (or a digest of it), pulling anything newer. It is slower and heavier but guarantees convergence. Practical systems combine both: rumour-style spreading for fresh changes, plus periodic full-state sync. memberlist calls the second one push/pull sync over TCP; Cassandra’s gossip exchange is digest-based anti-entropy every round. Bulk data repair with Merkle trees is the same idea applied to stored data, covered in quorum systems.

Membership and cluster state: Cassandra as an example

In Cassandra, every node runs a gossip task once per second, exchanging state with one random live peer and, at times, an unreachable node or a seed. Each node’s state has a generation (set at process start, so a restart is recognizable) and a version that increments with every change, plus application states such as status (normal, joining, leaving), load, schema version, tokens and data center. A digest exchange (“I have node X at generation g, version v”) lets peers request only what is newer.

sequenceDiagram
participant A as Node A
participant B as Node B
A->>B: SYN, digests (X: g1 v12, Y: g3 v40)
B-->>A: ACK, newer state for X (v15), request Y (B has v38)
A->>B: ACK2, full state for Y at v40
Note over A,B: both now hold the newest version of X and Y

Two details matter. First, failure detection is local: each node runs phi accrual on the gossip it receives and marks peers up or down in its own view, which affects where it routes requests. Second, being marked down is not the same as leaving the cluster: tokens are not reassigned until an operator decommissions or removes the node. That separation stops a flaky network from triggering mass data movement. Seeds help new nodes bootstrap and keep gossip from splitting into islands; they are not special for any other purpose.

Gossip-based membership converges eventually. Two nodes can briefly disagree about who is alive, which is acceptable for routing but not for deciding a single leader. When you need agreement, use consensus or a lease in a coordination service, as in leader election. Consul does exactly this split: gossip for agent membership and health, Raft among servers for the catalog and locks.

Where it breaks: gray failures

The hardest failures are not crashes. In a gray failure, a component is broken from the point of view of its users but looks healthy to its failure detector. Huang and colleagues (HotOS 2017) named the core issue differential observability: the detector and the clients observe the system differently.

Examples:

  • The heartbeat thread runs on its own thread pool and answers instantly, while the request thread pool is deadlocked.
  • A NIC drops 2% of large packets. Small health-check packets pass; 1 MB responses time out.
  • A disk is slow, not dead: writes take 800 ms, so the database is “up” but every transaction blows its timeout.
  • One availability zone’s path to a dependency is broken, so nodes in that zone fail requests while passing their local checks.
flowchart LR
HC["Health checker<br/>small ping every 1 s"] -->|"ok in 1 ms"| N["Node<br/>(heartbeat thread healthy)"]
CL["Clients<br/>real requests"] -->|"40% time out"| N
N --> D["Slow disk<br/>800 ms writes"]
style HC fill:#E1F5EE,stroke:#0F6E56,color:#085041
style CL fill:#FCEBEB,stroke:#A32D2D,color:#791F1F
style D fill:#FAEEDA,stroke:#854F0B,color:#633806
style N fill:#FAEEDA,stroke:#854F0B,color:#633806

Defences:

  • Probe what users touch. Health checks should exercise the real request path (with care not to depend on shared dependencies, or one database blip ejects every node).
  • Observe from clients. Passive outlier detection, as in Envoy, ejects a host because real requests to it fail or are slow, not because it missed a ping. Circuit breakers do the same per dependency (see circuit breaker).
  • Multiple vantage points. SWIM’s indirect probes and Lifeguard’s confirmations are a small version of this; at fleet level, compare a node’s error rate against its peers.
  • Prefer degrade over evict. A suspect node can get less traffic before it gets none, which limits the cost of a false positive.
  • Rate-limit membership changes. Cap how many nodes may be evicted per minute, so a detector gone wrong cannot drain the cluster, which is exactly what happened in the opening scenario.

Other failure modes to plan for: asymmetric partitions where A can reach B but not the reverse; flapping from a threshold set too tight; and gossip storms after a mass restart when every node has news at once. Monitoring these signals is covered in logs, metrics and traces.

Real-world systems

  • Apache Cassandra: once-per-second gossip with generation and version digests, phi accrual detection with phi_convict_threshold defaulting to 8, seeds for bootstrap, local up and down views.
  • HashiCorp memberlist (Consul, Serf, Nomad): SWIM with Lifeguard, piggybacked dissemination, periodic TCP push/pull full-state sync, separate LAN and WAN configurations.
  • Consul: gossip pools for membership and failure detection, plus a Raft cluster of servers for the strongly consistent catalog and key-value store.
  • Akka and Apache Pekko clusters: phi accrual heartbeats between nodes with gossip of cluster membership state.

How to apply it

Situation Approach
Under about 10 nodes, one coordinator is fine Heartbeats to a consensus store, lease-based membership
Hundreds to thousands of nodes SWIM or memberlist style gossip, phi or suspicion timeouts
Need one agreed leader or config Consensus (etcd, Consul servers), not gossip
Noisy cloud network Raise phi threshold or suspicion multiplier; measure false positive rate
User-facing health Client-side outlier detection plus real-path checks

Checklist:

  1. Write down the detection time you need and the false positive rate you can afford, then pick timeouts from both.
  2. Separate “suspected down” (route around it) from “removed” (move data), and make the second slower or manual.
  3. Cap the rate of evictions.
  4. Watch the detector: false suspicions per hour, refutations, flaps per node.
  5. Test with packet loss and CPU starvation, not just process kills, as in chaos engineering.

Interview angle

Interview questions

Q1: Why does SWIM use indirect probes and a suspicion state instead of declaring a node dead after one missed ping?

A missed ping may mean the target is dead, the path from the prober to the target is lossy, or the prober itself is overloaded. Indirect probes through k other members test different paths, so a single bad link does not cause a false declaration. The suspicion state gives a live but slow node time to refute by gossiping a higher incarnation number. Together they cut false positives sharply while still detecting real crashes within a few protocol periods, at constant message load per node.

Q2: How does a phi accrual detector differ from a fixed timeout?

A fixed timeout outputs suspected or not after a constant silence. Phi accrual tracks the distribution of recent heartbeat inter-arrival times and outputs phi, the negative log10 of the probability that a healthy node would be this late. The application sets a threshold on phi, which expresses an acceptable false positive rate rather than a number of seconds. Because the distribution is learned, the detector waits longer on a jittery network and convicts faster on a stable one.

Q3: Your load balancer health checks pass, but users see 30% errors from one host. What is going on and what do you change?

That is a gray failure caused by differential observability: the health check observes something different from what users experience, for example a heartbeat thread that is healthy while the request pool is stuck, or small probe packets passing while large responses are dropped. Change detection to observe the real path: passive outlier detection on actual request errors and latency, health checks that exercise the request path without depending on shared downstreams, and comparison against peer hosts. Also cap how many hosts can be ejected at once so the fix cannot drain the fleet.

✅ Key takeaways

  • A failure detector trades detection speed against false suspicion; no timeout is right under all network conditions.
  • Phi accrual outputs a suspicion level learned from heartbeat history; a threshold of 8 means about one in a hundred million chance of a false call under the model.
  • SWIM keeps load constant per node with random probes, indirect ping-req and a suspicion phase refuted by incarnation numbers; Lifeguard adds local health awareness and dynamic suspicion timeouts.
  • Gossip reaches N nodes in O(log N) rounds: about 8 rounds for 1,000 nodes at fanout 3. Anti-entropy sync guarantees convergence.
  • Gossip gives eventually consistent membership; use consensus when you need one agreed answer.
  • Gray failures come from differential observability: measure what clients experience and rate-limit evictions.

🧠 Check your understanding

0 / 4
  1. 1A SWIM member's direct ping to node B times out. What happens next?

  2. 2With push gossip at fanout 3, roughly how many rounds does it take to inform all of a 1,000-node cluster?

  3. 3What does a phi value of 3 mean in a phi accrual detector?

  4. 4Health checks pass on a host that times out 30% of real requests. Which fix addresses the root cause?

Where to go next

Finished this lesson?

Mark it complete to track your progress across the roadmap.