Full answer
The problem
A cluster of 2,000 nodes must know who is alive. Having every node ping every other node is about 4 million messages per round, and a central monitor is a single point of failure.
How gossip works
Every second (one round), each node:
- Picks k random peers (often 1 to 3).
- Sends its view: a list of members with heartbeat counters and versions of any shared state.
- Merges what it receives, keeping the newer version of each entry.
If one node learns something new, after one round about 2 nodes know it, then 4, then 8. With 2,000 nodes, about log2(2,000), roughly 11 rounds plus a few for the long tail, reach almost everyone. Each node's work per round is constant, so total traffic grows only linearly with cluster size.
Styles:
- Push: send your news. Pull: ask for theirs. Push-pull converges fastest.
- Anti-entropy: periodically compare full state (or Merkle tree summaries) to fix anything missed.
- Rumour mongering: spread a new item for a limited number of rounds, then stop.
Failure detection with SWIM
Heartbeats through gossip detect failures, but slowly and with false alarms. SWIM improves this:
- Node A pings a random node B directly.
- If there is no reply, A asks k other nodes to ping B for it (indirect probe), which separates "B is down" from "the A-B link is bad".
- If still no reply, B is marked suspect and this is gossiped; B can refute it by gossiping a higher incarnation number. After a timeout, B is declared dead.
Phi-accrual detectors (used by Cassandra and Akka) output a suspicion level based on heartbeat arrival history rather than a fixed timeout.
Where it is used
Cassandra and other Dynamo-style stores (membership and token ownership), Consul and Serf (membership and events), and cluster schedulers.
Trade-offs
- Propagation is probabilistic and takes seconds; it is not consensus. Decisions that need agreement (who is the leader, committed writes) use Raft or Paxos instead.
- Message size grows with state; large clusters gossip digests and fetch details only when versions differ.
- Network partitions produce two views until healed; anti-entropy fixes them afterwards.
By level
Fresher: Explain that each server shares news with a few random others each second, and the news spreads quickly to everyone. A fresher should see why this is cheaper than everyone messaging everyone.
Mid: Give the log n reasoning, push and pull styles, anti-entropy and SWIM indirect probes. Name systems that use gossip.
Senior: Discuss phi-accrual detection, incarnation numbers, digest-based exchange, partitions and the line between gossip and consensus. Expect convergence estimates.
Key points
- Each round, nodes exchange state with a few random peers
- Information reaches all nodes in about log n rounds
- Constant work per node per round, so it scales
- SWIM uses indirect probes and suspicion to reduce false failures
- Gossip gives eventual propagation, not consensus
Common mistakes
- Using all-to-all heartbeats in large clusters
- Treating gossip as a way to agree on a leader
- Declaring nodes dead on one missed heartbeat
- Sending full state every round as clusters grow
Follow-ups
- How does Cassandra use gossip for token ownership?
- What is the incarnation number in SWIM for?
- How would you estimate convergence time for 10,000 nodes?
Tips
- Explain the doubling intuition with numbers
- Describe indirect probing
- State clearly what gossip cannot do
Evaluation rubric
- Correct gossip mechanics and log n spread
- Explains failure detection and false positives
- Names real uses
- Clear limits compared with consensus