← Lab

Gossip Protocol

Watch epidemic-style gossip spread through a cluster. Click nodes to infect, kill, or revive them.

Scenarios:
Click a node to infect (patient zero), kill, or revive it.
Round: 0 · Infected: 0/9 · Fanout: 2 · Messages: 0 · Redundant: 0
Click a node to infect it and press Start.

How Gossip Protocols Work

Gossip protocols spread information the same way epidemics spread disease. A node that learns something new (gets "infected") tells a few randomly-chosen peers each round. Those peers tell a few more, and so on. The result is an exponential spread that quickly saturates the cluster.

The math is simple: if each infected node tells f peers per round (the fanout), the number of infected nodes roughly doubles each round when the cluster is mostly uninfected. But as more nodes already know the information, many messages become redundant — the target already has it. This creates the characteristic S-curve: slow start, rapid exponential growth, then saturation as the last few nodes get reached.

What makes gossip robust is the random peer selection. There's no fixed communication topology, no critical path, no single point of failure. If a node dies, other nodes simply gossip to different peers. Even with several nodes down, information still reaches every living node — it just takes an extra round or two. This is fundamentally different from tree-based broadcast, where losing one node can cut off an entire subtree.

The trade-off is redundancy. Since peers are chosen randomly, nodes that are already infected will still receive gossip messages. This wasted work is the cost of reliability. Higher fanout means faster convergence but more redundant messages. In practice, a fanout of 2–3 is enough to reliably infect a cluster of hundreds of nodes in O(log N) rounds.

Gossip is used everywhere: Cassandra and DynamoDB use it for failure detection and cluster membership (the SWIM protocol). Bitcoin propagates transactions via gossip. Consul, Serf, and HashiCorp's memberlist library all use gossip for service discovery. Any time you need information to spread reliably without centralized coordination, gossip is a strong choice.