SysDesignAtlas

Gossip Protocols & Failure Detection

How thousands of nodes agree on who is alive without a coordinator, epidemic dissemination, and why suspicion beats a binary alive/dead verdict.

HLDMedium9 min readgossipmembershipfailure-detectionepidemic
Confidence

#The membership problem

Every distributed system needs to know which nodes exist and which are alive. The obvious approaches don't scale:

Central registry. One service tracks membership. Simple, and it's a single point of failure that every node depends on continuously.

All-to-all heartbeats. Every node pings every other node. At N nodes that's N² messages per interval — 1,000 nodes at 1-second heartbeats is a million messages per second of pure overhead. It works to a few hundred nodes and then stops.

Gossip solves this with randomness: each node periodically picks a few random peers and exchanges what it knows. Information spreads like an epidemic.

#Why it spreads so fast

Each round, the number of informed nodes roughly multiplies:

   round 0:  1 node knows
   round 1:  2-3 know
   round 2:  ~6 know
   round 3:  ~15 know
        ...exponential...

   Convergence time ≈ O(log N) rounds

1,000 nodes converge in about 10 rounds. A million nodes in about 20. With one-second rounds and 3 peers contacted each time, a cluster of 10,000 nodes learns a fact in roughly 10 seconds — using a constant, tiny amount of bandwidth per node.

That's the whole appeal: per-node cost is constant regardless of cluster size, and there's no coordinator to lose.

#Properties

Strengths:

  • Scalable — O(1) messages per node per round; total O(N), not O(N²).
  • Robust — no single point of failure. Because each node picks different random peers every round, a dead node or broken link just means the information arrives via someone else instead.
  • Self-healing — a node that misses updates gets them in a later round. Message loss just slows convergence slightly.
  • Simple — no election, no leader, no configuration to keep consistent.

Weaknesses, and these determine where you can use it:

  • Eventually consistent. There's a window where nodes disagree. You can say "after 15 rounds, almost certainly everyone knows", but never "after 15 rounds, guaranteed" — the randomness could, very rarely, keep skipping one node.
  • Redundant messages. Nodes receive facts they already know — that's the price of not coordinating.
  • No strong guarantees. Gossip is for convergent, mergeable information, never for decisions requiring agreement. Membership rumors, yes; "who is the leader," no — that needs consensus.

#Gossip styles

Push — "here's what I know." Fast at the start, wasteful at the end (most recipients already know).

Pull — "what do you know that I don't?" Efficient once most nodes are informed.

Push-pull — exchange both ways. Fastest convergence in practice, and what most implementations use.

Two gossip styles, and production uses both. Anti-entropy means constantly comparing your entire picture of the world with a peer's and fixing any differences — thorough, slower, and guaranteed to catch up eventually. Rumour-mongering means only passing on things you just learned, and going quiet about them once they seem widely known — far cheaper, with a small chance a node misses a fact entirely. Production systems combine them: rumor-mongering for speed, periodic anti-entropy as a correctness backstop.

To keep messages small, nodes exchange digests first — a short summary like "I have node-7's info at version 12, node-9's at version 4". Each side then sends only the entries where the other is behind — the same principle as the Merkle tree comparison used for data repair.

#Failure detection

Detecting failure is fundamentally a guess. A node that hasn't responded may be dead, partitioned, garbage-collecting, or simply slow. From the outside, all of these look identical: silence. This is the same fact behind the FLP impossibility result in consensus — you can never tell a dead node from a very slow one.

#Naive: fixed timeout

"No heartbeat in 5 seconds → dead."

The problem is that one threshold can't be right for all conditions. Under load, healthy nodes miss heartbeats and get falsely evicted — which reduces capacity, increases load on survivors, and causes more false positives. That's a cascading failure triggered entirely by the failure detector.

#Phi accrual failure detection

Instead of answering "alive or dead?", answer "how surprised am I that I haven't heard from you?" — a suspicion level that rises as the silence grows, judged against how regularly that particular peer normally checks in. A node that always replies in 10 ms becomes suspicious after 100 ms; one whose replies normally vary between 10 ms and 2 s is given much longer before anyone gets suspicious.

   Track the recent inter-arrival intervals for each peer.
   Given the time since the last heartbeat, compute:

     φ = -log10(P(heartbeat is later than this | history))

   φ = 1  → ~10% chance we're wrong to suspect
   φ = 2  → ~1%
   φ = 8  → ~0.000001%

   Each caller picks its own threshold for its own risk appetite.

In plain terms: each node remembers the gaps between a peer's recent heartbeats. When a heartbeat is late, it asks "given those past gaps, how unlikely is a silence this long?" φ is that unlikeliness on a log scale — every +1 means ten times less likely that the peer is merely running late.

Why this is better: it adapts. On a fast, stable network the detector becomes sensitive; on a jittery one it becomes tolerant automatically — no manual tuning per environment. And different consumers can act at different confidence levels: stop routing new work at φ=3 (cheap, reversible), trigger a failover at φ=8 (expensive, disruptive).

Used by Cassandra and Akka. Naming it is a strong signal, because it shows you understand that failure detection is probabilistic rather than binary.

#SWIM

The protocol most modern systems use (HashiCorp Serf and Consul, among others). Its key idea: before declaring a node dead, ask other nodes to check too — because the silence might be about the path between you two, not about that node at all.

   1. Node A picks random node B, sends a direct ping.
   2. No response? A does NOT declare B dead.
   3. A asks k other random nodes to ping B on its behalf.
        ┌─► C ──ping──► B
   A ───┼─► D ──ping──► B      (indirect probes)
        └─► E ──ping──► B
   4. If ANY indirect probe succeeds → B is fine; the problem
      was the A↔B path specifically.
   5. If all fail → mark B SUSPECT (not dead), and gossip that.
   6. B, on hearing it's suspected, refutes with a higher
      incarnation number.
   7. No refutation within a timeout → CONFIRMED dead.

Three ideas make this good, and each is worth naming:

  • Indirect probing distinguishes "B is down" from "the network path from A to B is down." This eliminates a large class of false positives caused by localized network problems.
  • The suspect state gives a node a chance to defend itself before eviction — a GC-paused node returns, refutes, and stays in the cluster.
  • Incarnation numbers let a node override stale rumors about itself. Each node keeps a counter that only it may increase. When it hears "B is suspect (incarnation 4)", it gossips "B is alive (incarnation 5)", and everyone trusts the higher number. That stops an old "suspect" message still circulating from evicting a healthy node later.

#Where gossip is used

  • Cassandra / ScyllaDB — cluster membership, node state, schema versions, token ownership.
  • Consul / Serf — the SWIM-based membership layer underneath the consensus layer.
  • Redis Cluster — node discovery, slot assignment propagation, failure detection.
  • Blockchain networks — transaction and block propagation across untrusted peers.
  • CDN and cache clusters — invalidation propagation.

The recurring architectural pattern is worth internalizing:

   GOSSIP LAYER            membership, health, metadata
                           → scalable, eventually consistent,
                             no coordinator

   CONSENSUS LAYER         leader election, config decisions
                           → strongly consistent, small,
                             built ON TOP of known membership

Gossip answers "who is here?" cheaply at any scale. Consensus answers "what have we decided?" correctly for a small set of critical facts. Using the wrong one for the other job — gossiping decisions, or running consensus over membership churn at 10,000 nodes — is the mistake this split avoids.

#Check yourself

Why don't all-to-all heartbeats scale?Show answer
N nodes send N² messages per interval — a million a second at 1,000 nodes. Gossip costs a constant number of messages per node, so the total grows only linearly.
How fast does gossip spread, and why?Show answer
In about log N rounds — roughly 10 rounds for 1,000 nodes and 20 for a million — because the number of informed nodes multiplies each round, like an epidemic.
Anti-entropy versus rumour-mongering?Show answer
Anti-entropy constantly compares full state with a peer — thorough and guaranteed to catch up. Rumour-mongering only passes on new facts until they seem widely known — cheap, but may miss a node. Production uses both.
What must never be decided by gossip?Show answer
Anything needing agreement, such as who the leader is or who owns a shard. Gossip is eventually consistent; decisions belong to consensus, built on top of gossiped membership.
Why can a fixed failure-detection timeout cause a cascade?Show answer
Under load, healthy nodes miss heartbeats and get evicted, which shrinks capacity, loads the survivors further and causes more false evictions.
What does phi accrual failure detection output instead of alive/dead?Show answer
A suspicion level based on how unusual the current silence is for that particular peer's history. It adapts to network jitter, and each caller picks its own threshold — reroute at low φ, fail over at high φ.
Name SWIM's three key ideas.Show answer
Indirect probing — ask other nodes to ping a silent one, separating a dead node from a bad network path; a suspect state so a paused node can refute; and incarnation numbers so a node can override stale rumours about itself.

#What to carry forward

  • Gossip spreads facts in about log N rounds at constant cost per node, with no coordinator.
  • It's eventually consistent: use it for membership and metadata, never for decisions.
  • Combine fast rumour-mongering with periodic anti-entropy, exchanging digests first.
  • Failure detection is a guess: prefer phi accrual and SWIM's indirect probes and suspect state over fixed timeouts.
  • Typical stack: gossip for "who is here", consensus for "what have we decided".
00:00
/ 9m