Skip to content

Gossip Protocols in Go: Why a Rumor Reaches Every Node in Logarithmic Time

November 23, 2026 · 8 min read · Lire en français

Contents

How long does it take one piece of news to reach 100,000 machines when nobody is in charge, nobody broadcasts, and each machine may only talk to one random peer per round? About 29 rounds. With a smarter exchange rule, about 14.

The number is small for the same reason rumors and epidemics spread so fast: each person who learns the news becomes a new source. This article derives that with a few lines of math, then checks every formula against a Go simulation. It is the fourth in a series on the math inside distributed systems, and it follows the CRDT article: CRDTs say how to merge states without conflict, and gossip is how those states travel through a cluster that has no coordinator.

The idea: pass it on to a random peer

A gossip protocol (also called epidemic protocol) has one rule. Every round, each node picks a peer at random and exchanges information with it. There is no leader, no list of who knows what, and no broadcast to everyone. A node that dies or is slow only removes itself from the exchange, so the protocol keeps working.

There are three ways to exchange:

  • Push: an informed node sends the news to its chosen peer.
  • Pull: every node asks its chosen peer whether it has news.
  • Push-pull: the two nodes swap what they know in both directions.

The three behave the same at the start and very differently at the end, and the math explains why.

The math: doubling, then a tail

Call a node informed if it has the news and susceptible if it does not, the vocabulary of epidemiology. Let s_t be the fraction of susceptible nodes after round t.

Phase 1: exponential growth

Start with one informed node. In push, each informed node contacts one node per round. While almost everyone is still susceptible, almost every contact lands on a new node, so the number of informed nodes doubles each round: 1, 2, 4, 8, and so on. After t rounds about 2^t nodes know. Half the cluster is reached when 2^t ≈ N/2, after about log₂ N rounds. For 100,000 nodes, log₂ N is 16.6.

This is a logistic (S-shaped) curve: a slow start, an explosion in the middle, and a slow end. Here is one push run on 100,000 nodes, showing the share of nodes still uninformed:

Round1014161820222430
Still uninformed99.0%85.4%56.8%19.5%3.5%0.55%0.07%0%

Half the nodes are informed around round 16 to 17, right at log₂ N. The first ten rounds barely move the number, then it collapses.

Phase 2: the tail, and why push and pull differ

Once most nodes are informed, the doubling stops, because most contacts now land on nodes that already know. What happens to the last few susceptible nodes depends on the mode.

Push. With about N informed nodes each contacting a random node, the chance that a given susceptible node is not contacted by any of them in a round is (1 − 1/N)^N ≈ 1/e ≈ 0.37. So each round multiplies s by about 1/e:

s_{t+1} ≈ s_t / e

This is exponential decay, and it is slow: from s = 1/2 down to 1/N takes about ln N more rounds. Total for push: about log₂ N + ln N rounds, a result due to Pittel in 1987. For 100,000 nodes that is 16.6 + 11.5 = 28.1.

Pull. A susceptible node asks a random node for news. It stays susceptible only if the node it asked is also susceptible, which happens with probability s_t. So:

s_{t+1} ≈ s_t²

Squaring is far stronger than dividing by 2.7. The uninformed share goes 10⁻¹ → 10⁻² → 10⁻⁴ → 10⁻⁸: the number of digits doubles every round. The tail of pull takes only about log₂ log N rounds. This is why pull finishes off the last stragglers quickly, while push lingers on them. The price is traffic: every node asks every round, even long after it has learned the news, as the message counts below show. That is why the best protocols combine both.

Push-pull does both in each exchange, so it inherits the fast doubling and the fast tail.

Simulating it in Go

The simulation is synchronous: every round, each node picks one other node uniformly at random. The core is one function:

func round(inf []bool, mode Mode, r *rand.Rand) {
    n := len(inf)
    next := make([]bool, n)
    copy(next, inf)
    for i := 0; i < n; i++ {
        j := r.Intn(n - 1) // a random peer other than i
        if j >= i {
            j++
        }
        switch mode {
        case Push: // informed i tells j
            if inf[i] {
                next[j] = true
            }
        case Pull: // i asks j
            if inf[j] {
                next[i] = true
            }
        case PushPull: // swap in both directions
            if inf[i] || inf[j] {
                next[i], next[j] = true, true
            }
        }
    }
    copy(inf, next)
}

Updating a copy (next) keeps the round synchronous: everything that happens in round t is based on the state at the start of round t.

Rounds until every node is informed

Averages over 20 runs per cell:

Nodes (N)log₂ N + ln NPushPullPush-pull
10011.212.29.96.5
1,00016.917.513.89.2
10,00022.523.617.411.4
100,00028.129.220.913.9

Push follows log₂ N + ln N within about one round, as predicted. Growing the cluster a thousand times, from 100 to 100,000, costs push only 17 more rounds. That is the point of the whole approach: the cost grows with the logarithm of the cluster size. Pull and push-pull are clearly faster, and push-pull needs half the rounds of push at 100,000 nodes.

Checking the tail formulas

On 100,000 nodes, in the tail where fewer than 5% are uninformed:

  • Push: in the first rounds of the tail, s shrank by factors of 0.41, 0.38, 0.38 and 0.34 from one round to the next, close to the predicted 1/e ≈ 0.37.
  • Pull: the uninformed share went 5.5×10⁻² → 3.1×10⁻³ → 1.0×10⁻⁵. Squaring the previous values predicts 3.0×10⁻³ and 9.4×10⁻⁶. A match to two digits.

What it costs in messages

Counting contacts started per node until completion, on 10,000 nodes: push used 9.7, pull 17.4, push-pull 11.7. Push is cheapest per node because only informed nodes send, but it takes the most rounds. Pull makes every node ask every round, even long after it learned the news. Push-pull spends about 20% more contacts than push and finishes in half the rounds, which is why it is the common choice.

Where it is used

  • Membership and failure detection. Nodes gossip who is alive. SWIM-style protocols, used in HashiCorp's memberlist (behind Serf and Consul), add a probe-then-suspect step so a single missed reply does not declare a node dead.
  • Databases. Cassandra nodes gossip cluster state (who joined, who is down, schema versions) roughly once per second.
  • CRDT delivery. Because merging is commutative, associative and idempotent, gossip's random, repeated, out-of-order delivery is harmless. This is the pairing from the previous article.

Limits

  • It is probabilistic. "Every node, in O(log N) rounds" holds with high probability, not with certainty. A rare node can be missed for a few extra rounds.
  • Bad news travels as fast as good news. A corrupted or stale value spreads exponentially too. Amazon's account of its July 2008 S3 outage traced it to corrupted messages spreading through the system's gossip. Gossiped data needs checks, versions or signatures.
  • Redundancy. Late in the process, most messages go to nodes that already know. That waste is the price of having no coordinator, and it is why systems tune how often and how widely they gossip.
  • My simulation is idealized. Rounds are synchronous, peers are chosen uniformly from all nodes, and no messages are lost or delayed. Real clusters are asynchronous, use partial views of the membership, and lose packets. The log N shape survives, the constants do not.
  • Fanout. Contacting k peers per round instead of one multiplies the early growth by (1 + k) per round, so the doubling phase shortens to about log_{k+1} N rounds (derived here, not measured), at k times the traffic.

Takeaways

  • Gossip has one rule: each round, exchange information with a random peer. No leader, no global list, and no single point of failure.
  • Early on, informed nodes double each round, so reaching half the cluster takes about log₂ N rounds.
  • In the tail, push multiplies the uninformed share by 1/e per round (slow), while pull squares it (very fast). Push-pull combines both.
  • Measured: push needs about log₂ N + ln N rounds, 29 for 100,000 nodes. Push-pull needs 14.
  • Growing the cluster a thousand times adds only a handful of rounds, which is why gossip scales.
  • Gossip spreads corrupted data as fast as valid data, so what you gossip needs validation.

Next in the series: Bloom filters and HyperLogLog, trading a small, controlled error for a large saving in memory.

Subscribe to future posts

Get future posts in your inbox. No spam, unsubscribe any time.

Powered by Buttondown.

Related posts

© 2026 < Denis AKPAGNONITE /> | N1BBzerLZXT