Video in progress

Strong Middle 🏗️ System design

How do nodes in a cluster find out that another one has failed, and what does the gossip protocol give here?

Every node periodically passes the state it knows (who is alive, heartbeat counters) to a few random neighbors, and the information spreads across the cluster like an epidemic. No central coordinator is needed; but the conclusion "it's dead" is probabilistic, so a timeout and a "suspect" stage are used.

📖 Answer

The central monitoring variant: every node sends a heartbeat to a central server every second. It's simple, but the center is itself a single point of failure, and with 1000 nodes it carries a heavy load.

In gossip, every second each node picks 2–3 random nodes and sends its list: "A — heartbeat 1052, B — 988, C — 1201...". The receiver takes the newer values. The information reaches the whole cluster in log(N) rounds — about 10 rounds with 1000 nodes. Each node's load barely depends on the cluster size.

If C's heartbeat counter doesn't increase for a long time, we mark it "suspect", then "dead".

The hard part is telling "slow" from "dead". The network dropped for a second, a GC pause happened — the node is alive but didn't answer. So:

  • SWIM style: A pings B, and if there's no reply, it asks other nodes "try pinging B yourself" (an indirect probe) — so a network problem between A and B doesn't kill B;
  • the phi accrual detector (Cassandra, Akka): instead of a fixed timeout, it derives a "probability of being dead" from the distribution of times between heartbeats and compares it to a threshold.

Where you see it: Cassandra (membership and state), Consul/Serf (SWIM), Redis Cluster (the cluster bus between nodes), Akka Cluster.

An important difference: gossip gives eventual agreement on "who is alive". It isn't enough for strict agreement like who the leader is — that needs Raft or a similar consensus.