Saltar al contenido principal

Who's Alive? Gossip, SWIM, and Membership That Scales

· 10 min de lectura
Clustron Team
Ingeniería de Sistemas Distribuidos

Every node in a cluster needs an answer to a deceptively simple question: which of my peers are still alive? Routing decisions, replica placement, ownership, and quorum all depend on that answer, and a node working from a stale one does real damage — it keeps forwarding writes to a peer that died ten minutes ago, or it refuses to use a node that recovered and is sitting idle. The membership view is infrastructure that everything else stands on.

The obvious way to maintain it is to have every node heartbeat every other node, and it is exactly the design that stops scaling. N nodes each pinging N−1 peers every interval is a quadratic message storm, and the traffic grows with the square of the cluster just as the cluster is the thing you wanted to grow. Centralizing the health check into one registry does not help: it trades the message storm for a bottleneck that every node must reach and a single point whose failure blinds the whole cluster.

The scalable answer borrows two ideas from how rumors and infections spread. First, you do not need to check everyone yourself; you need the information about who is alive to reach everyone, and information spreads fastest when each node tells a few random others, who tell a few random others, covering the cluster in a logarithmic number of rounds. Second, you do not need to probe every peer to find a failure; you probe one random peer per round and let the math of repetition cover everyone over time. The protocol that combines these cleanly is SWIM — Scalable Weakly-consistent Infection-style process group Membership — and it splits the job into two independent pieces: detecting that a node failed, and disseminating that fact. This post takes each in turn.

Detection: one random probe per round​

In SWIM, each node does a small, fixed amount of work per protocol period, no matter how large the cluster is. Every period it picks one peer at random and sends it a ping, expecting an acknowledgement within a timeout. That is the entire per-node detection cost: a single ping and ack per period, O(1) in the cluster size, against the O(N) of all-to-all heartbeating. Random selection means that over many periods every peer gets probed, and across the cluster some node is checking some peer continuously — the detection coverage is collective, not individual, and the per-node load stays flat as you add nodes.

The catch is that one node probing one peer is a weak observer, and acting on a single missed ack is how you manufacture false alarms.

The indirect probe: dead, or just slow?​

A missed ack does not mean the peer is dead. It could be a dropped packet, a garbage-collection pause, or a momentarily congested link between exactly these two nodes — the dead-or-slow ambiguity that every failure detector has to face. Declaring death on one timeout is expensive, because a false positive triggers ownership moves and rebalancing for a node that never actually left, and then triggers them all over again when it turns out to be fine.

SWIM's defense is the indirect probe. When A's direct ping to B times out, A does not conclude anything; it picks k other random nodes and asks each of them to ping B on its behalf. If B is alive but the direct A–B path was bad, one of the k alternate paths very likely gets through, and the relayed ack clears B. Only if the direct ping and all k indirect pings fail does A move B toward failure. This is the dead-or-slow problem answered at the protocol level: never trust a single observer on a single path, because the path is as likely to be at fault as the peer.

ABalive, slow pathCDdirect ping → timeout"probe B for me"indirect pingsack relayed: B is alive ✓only if the direct ping AND all k indirect pings fail does A mark B suspect — and then it gossips the suspicion

Suspicion: accuse before you convict​

Even after a direct and indirect failure, SWIM does not jump straight to "dead." It marks the peer suspect and gossips that suspicion to the cluster, opening a window in which the accusation can be refuted. A node that hears it has been suspected — or any node that can still reach it — pushes back with an alive message carrying a higher incarnation number, a per-node counter that lets a node override stale rumors about itself. If the suspicion window times out with no refutation, the suspect is promoted to confirmed dead and gossiped as such.

The incarnation number is what makes the rumor mill safe. Because a node can always out-vote an old "suspect" or "dead" about itself by bumping its own incarnation, a brief false suspicion self-corrects instead of permanently evicting a node that was only slow. Accusations are cheap and reversible; conviction is deferred until the node has had a fair chance to answer.

Dissemination: gossip that rides along​

Membership changes — joins, graceful leaves, suspicions, confirmations — do not get their own messages. SWIM piggybacks them on the ping and ack traffic already flowing for failure detection: every message carries a few recent updates, a receiver applies them and forwards them on its own future pings, and an update started at one node reaches the whole cluster in O(log N) rounds. There is no multicast and no coordinator, and the spread is robust precisely because no single path matters — lose a node or a link and the rumor simply takes another route. It is the same anti-entropy instinct behind reconciling replicas, aimed at the membership list instead of the keyspace.

// One SWIM protocol period at node A — fixed work regardless of cluster size.
var target = members.RandomAlive(); // pick ONE peer, not all of them
if (await Ping(target, timeout)) {
gossip.Apply(ack.PiggybackedUpdates); // membership news rides on the ack
} else {
var helpers = members.RandomAlive(k, except: target);
var acked = await AnyAcks(helpers.Select(h => IndirectPing(h, target)));
if (!acked) // direct AND all k indirect failed
gossip.Suspect(target, incarnation[target]); // accuse, don't convict — and gossip it
}
// Elsewhere: a node that hears it is suspected refutes with a higher incarnation number.

What it costs​

The appeal is that every dial is bounded and independent of N. Detection is O(1) messages per node per period; dissemination adds only a small constant of piggybacked updates and converges in O(log N) rounds. The knobs trade cleanly against each other: more indirect probes k spend messages to buy fewer false positives, a longer suspicion timeout spends detection latency for the same, and a shorter period spends bandwidth for faster detection. No node depends on a coordinator, and nothing scales with the square of the cluster — which is what lets the membership layer underneath cluster formation and leader election stay cheap as the cluster grows.

Wrap-up​

A cluster that heartbeats all-to-all or leans on a central registry has built its membership view on a design that fails exactly when the cluster succeeds. SWIM replaces both with two epidemiological ideas: probe one random peer per period so detection load stays flat, and spread who-is-alive by infection so news reaches everyone in logarithmic rounds with no coordinator. The indirect probe keeps the detector honest about the dead-or-slow ambiguity by refusing to trust a single path, the suspicion-and-incarnation mechanism makes a false accusation cheap and self-correcting rather than a permanent eviction, and piggybacked gossip disseminates every change for free on traffic that was already flowing. The result is a membership view that is weakly consistent but converges fast, costs a constant per node, and degrades gracefully — the quiet foundation the rest of the cluster gets to assume.