Quick revision
The short answer
SWIM has each node ping one random member per protocol period; if no ack arrives in time, it asks k other members to ping the target on its behalf, so a single bad link cannot get a healthy node declared dead. A target that also fails the indirect pings becomes suspect rather than dead, and it can refute the suspicion by announcing a higher incarnation number, which only it may increase; if it does not refute within a timeout, it is declared dead. Membership updates piggyback on ping and ack messages and reach everyone in O(log N) periods, so each node sends a constant number of messages per period, unlike all-to-all heartbeats whose traffic grows with N squared.
What to remember
In this answer, we saw how SWIM replaces all-to-all heartbeats. Each period a node probes one random member, falls back to indirect pings through k others so that one bad link cannot condemn a healthy node, and marks unreachable members as suspect rather than dead. A suspect refutes with a higher incarnation number that only it may increase, and updates spread by piggybacking on probe traffic in O(log N) periods. The result is constant work per node per period instead of N-squared traffic, with Lifeguard making overloaded nodes slow their own judgements to cut false positives.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
SWIM has each node ping one random member per protocol period; if no ack arrives in time, it asks k other members to ping the target on its behalf, so a single bad link cannot get a healthy node declared dead. A target that also fails the indirect pings becomes suspect rather than dead, and it can refute the suspicion by announcing a higher incarnation number, which only it may increase; if it does not refute within a timeout, it is declared dead. Membership updates piggyback on ping and ack messages and reach everyone in O(log N) periods, so each node sends a constant number of messages per period, unlike all-to-all heartbeats whose traffic grows with N squared.
Why this question is asked
Heartbeating every node to every other node works for ten nodes and falls apart at a thousand. SWIM, short for Scalable Weakly-consistent Infection-style process group Membership, was designed to fix exactly that, and through HashiCorp's memberlist library it runs inside Consul, Serf and Nomad. Interviewers ask about its internals because each mechanism solves a specific real problem: lossy links, false suspicions and broadcast cost. In this answer, we will see why all-to-all heartbeats do not scale, then walk through SWIM's probing, suspicion with incarnation numbers, and piggybacked dissemination, and finish with the Lifeguard extensions.
1Why All-to-All Heartbeats Do Not Scale
In the naive approach, every node sends a heartbeat to every other node each second. With N nodes, that is N x (N - 1) messages per second. For 100 nodes it is about 10,000 messages per second, which is fine. For 1,000 nodes it is about a million, and every node must receive and process 999 heartbeats a second. The load grows with N squared, and every node's work grows with N.
SWIM's key idea is to separate two jobs that heartbeats mix together: detecting failures and spreading the news about them. Each can then be done with a constant amount of work per node.
2Probing With Indirect Pings
Time is divided into protocol periods, for example one second each. In every period, each node picks one member at random, going through a shuffled list so every member is probed regularly, and sends it a ping. If an ack comes back within a short timeout, all is well.
7 messages in order. Play them, or step through them one at a time.
The direct link A to B is bad, but C reaches B, so B stays alive.
If no ack arrives, A does not conclude that B is dead. The problem might be the network path between A and B, or A itself might be overloaded. So A asks k other random members, typically three, to ping B on its behalf with a ping-req message. If any of them gets an ack from B, they forward it to A, and B is considered alive. Only if neither the direct nor the indirect pings succeed by the end of the period does A take the next step. Notice what this buys: a single bad link between two nodes no longer gets a healthy node declared dead, because B has to be unreachable from several different places.
3Suspicion and Incarnation Numbers
Even then, A does not declare B dead. It marks B as suspect and spreads that suspicion to the group. A suspect member is still treated as part of the group, and it has a timeout to prove it is alive. If the suspicion reaches B, perhaps because B was only paused for a few seconds, B refutes it by announcing itself alive with a higher incarnation number.
The incarnation number is a counter attached to each member's state, and only the member itself may increase it. Other nodes apply a simple rule: a message about a member with a higher incarnation number overrides older messages about that member, and at the same incarnation, suspect overrides alive and dead overrides both. So when B, at incarnation 4, hears it is suspected at incarnation 4, it broadcasts alive at incarnation 5, and every node that receives that message drops the suspicion. If no refutation arrives before the suspicion timeout, the member is declared dead, and that is final for that incarnation.
| Message | Incarnation | Result at other nodes |
|---|---|---|
| B alive | 4 | B alive |
| B suspect (from A) | 4 | suspect overrides alive at same incarnation |
| B alive (from B itself) | 5 | higher incarnation: suspicion cleared |
| B suspect (late copy) | 4 | ignored: older incarnation |
4Spreading Updates by Piggybacking
The second job, telling everyone about joins, suspicions and deaths, needs no separate broadcast. SWIM attaches recent membership updates to the ping, ping-req and ack messages it is already sending. Each node keeps a small buffer of recent updates and includes a few of them in every outgoing message, each update being sent a limited number of times, on the order of log N.
This is infection-style dissemination: like a rumour, each update reaches new nodes with every period, and the number of informed nodes grows exponentially. An update reaches the whole group in O(log N) protocol periods, and it costs nothing extra in message count, only a few more bytes per message.
5Why It Scales, and the Lifeguard Extensions
Put together, each node in each period sends one ping, receives about one ping from someone else and sends the acks, plus at most k ping-reqs when something goes wrong. That is a constant number of messages per node per period, whatever the cluster size: for 1,000 nodes, a few thousand messages per second in total instead of about a million. Detection time stays constant on average, and dissemination grows only with log N.
In practice, the main remaining source of false positives is a node that is itself overloaded: it is slow to send pings and process acks, so it wrongly suspects healthy peers. HashiCorp's Lifeguard extensions, used in memberlist, address this. A node keeps a local health score that rises when it misses acks or has to refute suspicions about itself, and when that score is high it lengthens its own probe timeouts and periods. It also starts suspicion timeouts long and shortens them as independent confirmations arrive from other nodes. In other words, a node that might be the problem slows down its own judgements of others.
6Follow-up questions
Why are indirect pings sent to k random members rather than all of them?
Because a few independent paths are enough to rule out a single bad link, and asking everyone would bring back the N-squared cost. With k around three, the chance that all the indirect paths fail while the target is healthy is small, and the cost stays constant.
What happens if a node declared dead comes back?
It must rejoin with a higher incarnation number than the one at which it was declared dead, so the group treats it as a fresh alive member. Without that rule, old dead messages could keep overriding it.
Is SWIM's membership view strongly consistent?
No. It is weakly consistent, as its name says: different nodes may briefly see different membership. That is fine for discovery and failure detection, but anything needing a single agreed view, such as leader election, should use a consensus system like Raft on top, as Consul does for its servers.
7Conclusion
In this answer, we saw how SWIM replaces all-to-all heartbeats. Each period a node probes one random member, falls back to indirect pings through k others so that one bad link cannot condemn a healthy node, and marks unreachable members as suspect rather than dead. A suspect refutes with a higher incarnation number that only it may increase, and updates spread by piggybacking on probe traffic in O(log N) periods. The result is constant work per node per period instead of N-squared traffic, with Lifeguard making overloaded nodes slow their own judgements to cut false positives.
Open with
SWIM separates failure detection from spreading membership updates. For detection, in each protocol period every node pings one random member, cycling through a shuffled list. If no ack comes back in time, it doesn't declare the target dead; it asks k other members, usually three, to ping the target for it with ping-req.
Then, if they want more
If any of them gets an ack, the target is alive, so one bad link between two nodes can't get a healthy node removed. If the indirect pings also fail, the target becomes suspect, not dead. The suspicion spreads, and the suspected node can refute it by announcing itself alive with a higher incarnation number.
Only the node itself may increase its incarnation, and the rules are that a higher incarnation overrides older messages, and at the same incarnation suspect beats alive. If there's no refutation within the suspicion timeout, it's declared dead.
For dissemination there's no separate broadcast: updates piggyback on pings and acks, infection style, so they reach everyone in about log N periods. That's why it scales: each node sends a constant number of messages per period regardless of cluster size, whereas all-to-all heartbeats grow with N squared, about a million messages a second for a thousand nodes.
HashiCorp's memberlist, which Consul and Serf use, adds Lifeguard, where a node that's missing acks itself raises a local health score and slows its own timeouts, which cuts false positives from overloaded nodes.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Describe SWIM's probing with indirect pings, its suspicion mechanism with incarnation...": https://scrivio-interview-library.netlify.app/architecture/distributed-systems/1b13a6a04c/