Tiffin's cache cluster has 200 nodes. A new node joins. Every other node needs to learn its address and which keys it owns. A node dies. Everyone needs to stop sending it traffic. How does that news reach 200 machines?
One option is a central registry that everybody watches (Module 11's service discovery). That works, but the registry becomes something that must never be down. Another option is to have the node that noticed tell all 199 others directly. That's 199 messages per event, and if the sender crashes halfway, half the cluster never hears.
Gossip takes a third path: each node regularly tells a few random others what it knows, and they pass it on. News spreads the way a rumour spreads through an office, and it reaches everyone surprisingly fast.
How gossip works
Every node runs the same loop, say once a second:
- Pick one (or a few) other nodes at random.
- Exchange state with them: "here's what I know, what do you know?"
- Both sides keep the newer version of each piece of information.
That's all. No leader, no coordinator, no node more important than any other.
A gossip protocol spreads information by having every node periodically exchange state with a few randomly chosen peers. News reaches all N nodes in about O(log N) rounds, with no central point of failure.
Push, pull and push-pull
| Style | What happens | Strength |
|---|---|---|
| Push | I send you what I know | Spreads fast while few nodes know |
| Pull | I ask you what you know | Finishes fast when most nodes know and a few stragglers remain |
| Push-pull | We swap in one exchange | Best of both, and what most systems use |