Distributed systems · L2Failure detection and membership

Failure detection and membership

A cluster must decide when a node is dead, but it can never be sure. Learn how heartbeats, phi accrual and SWIM gossip make that guess, and what goes wrong after it.

L2 SeniorDistributed systems18 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 10 Nov 2026 · How we check content
Section 1 of 8

What broke

In September 2012, GitHub ran its main MySQL database on a 3-node cluster. A tool called Percona Replication Manager, running on Pacemaker, ran health checks on the primary. If the checks failed, it moved the "active" role to another server. 1

On Monday, a database migration put more load on the primary than the team had seen before. The primary was busy, not broken. But the load made its health checks fail. 1

So the cluster did what it was told. It moved the active role and the primary database to another server. 1

The new server had a cold cache, so it "performed rather poorly". Under real traffic, its health checks failed too. The active role moved back to the first server. 1

A GitHub engineer turned on Pacemaker's maintenance mode, which turns off all health checks and automatic failover. The site recovered slowly as the cache filled. After the incident, GitHub changed its setup so that only a person from operations starts a failover of the primary database. 1

The health check could not tell "busy" from "dead". Each wrong decision made the next server weaker.

Section 2 of 8

The idea in simple words

A cluster needs to know which nodes are alive. It uses that list to route requests, place data and pick leaders.

But you saw in Why distributed systems are hard that silence has many causes. A node can be dead, paused, overloaded, or behind a bad link. The SWIM paper puts it plainly: a process that loses messages looks the same as one that has failed. 5

So a failure detector can only guess. Every design picks a point between two mistakes:

  • Too fast: you mark healthy nodes dead. This is a false positive.
  • Too slow: a dead node keeps getting traffic for a long time.

The key idea. A failure detector does not find dead nodes. It finds nodes that are late. Choose how late counts as dead, and design what happens next so that a wrong guess is cheap.

Section 3 of 8

How it works

Heartbeats and a fixed timeout

The simplest design: each node sends a heartbeat every second. If you hear nothing for, say, 5 seconds, you call the node dead. Raft uses this idea for leaders. A follower that hears no heartbeat for one election timeout starts an election. You can read more in Consensus and Raft.

A load balancer health check is the same idea, but it asks instead of waiting. Load balancing covers those settings.

A fixed timeout has a problem. A good value on a quiet network is too short on a busy one. The phi paper calls this the trade-off between conservative and aggressive detection. 2

Phi accrual: a score, not a yes or no

Hayashibara and others proposed the phi accrual failure detector in 2004. It does not answer "trust" or "suspect". It gives a suspicion level on a continuous scale. The level keeps rising while no heartbeat arrives. 2

The phi detector keeps a window of recent gaps between heartbeats. From these, it learns what "normal" looks like. Then it asks: how unlikely is it that the next heartbeat is still on its way? 2

import math, statistics

def phi(now, last_beat, gaps):
    mean = statistics.mean(gaps)
    std = max(statistics.stdev(gaps), 0.1)  # avoid a zero spread
    late = now - last_beat
    # chance a heartbeat still arrives after this long
    p_later = 0.5 * math.erfc((late - mean) / (std * math.sqrt(2)))
    return -math.log10(max(p_later, 1e-300))

This is the formula Akka documents, using a normal curve. 3 Each step of 1 in phi means about ten times fewer mistakes. With a threshold of 1, about 10% of suspicions turn out wrong. With 2 it is about 1%, and with 3 about 0.1%. 2

Say heartbeats come every 1 second. With a spread of 0.1 seconds (the smallest the code allows), 1.6 seconds of silence gives phi of about 9. With a spread of 0.3 seconds, the same silence gives phi of only about 1.6. With a threshold of 8, the first node is suspected and the second is not. The detector adapts to the network you really have.

Akka and Cassandra both use a default threshold of 8. 3 4 Akka suggests 12 on cloud networks such as Amazon EC2. 3 A low threshold gives many wrong suspicions but finds crashes fast. A high one makes fewer mistakes but is slower. 3

SWIM: membership by gossip

Heartbeats raise a second problem: who talks to whom? If every node sends heartbeats to every other node, the network load grows with the square of the group size. 5

SWIM splits the job into two parts: failure detection and spreading the news. 5 Step through one probe round.

One SWIM probe: direct ping, indirect pings, then suspicionA B C D pingA pings B. No ack before the timeout. ping-reqping-reqA asks C and D: "please ping B for me" No ack comes back on any path A marks B: suspect (incarnation 1)The news rides on the next pings and acks B: "alive, incarnation 2"No reply before the suspicion timeout?Then: confirm, B is dead SeniorPath
  1. Each protocol period, A picks one member at random, here B, and pings it. No ack comes back within the timeout. Maybe B is dead. Maybe the path from A to B is congested.
  2. A does not decide alone. It sends a ping-req to a few other members, here C and D. Each one pings B and passes any ack back to A. These paths do not use the link between A and B.
  3. Nobody gets an ack from B. Now A has better evidence than one lost packet. But B could still be paused or overloaded.
  4. A marks B as suspect, not dead. It adds the message to the pings and acks it already sends. No extra messages are needed to spread it, and other members learn it like an infection.
  5. If B hears that it is suspected, it answers with a higher incarnation number. That Alive message cancels the suspicion. If no Alive message comes before the suspicion timeout, B is confirmed dead and removed.
Step 1 of 5

In each protocol period, a node pings one random member. If no ack comes in time, it sends a ping-req to k other members. They ping the target and relay any ack. This avoids blaming a node for congestion on one path. 5

If nobody gets an ack, the target is marked "suspect", not dead. A suspected node can refute this by sending an Alive message with a higher incarnation number. If the suspicion times out first, a Confirm message removes the node. 5

The news does not need its own messages. It rides on the pings and acks that are already flowing. The paper calls this infection-style dissemination. 5 The expected detection time and the load on each member do not grow with the size of the group. 5 SWIM is a gossip protocol: news spreads from node to node, with no central server.

Lifeguard: when the accuser is the slow one

The SWIM paper itself notes a weak spot. A slow process, for example one that drops packets from full buffers, can declare several healthy processes faulty. 5

HashiCorp hit this in memberlist, the library inside Serf, Consul and Nomad. CPU exhaustion, network delay or loss made members wrongly declare others faulty. 7 Their fix, Lifeguard, assumes the local failure detector may be the problem. 6 It has three parts: 7

  • Self-awareness. A node keeps a score of signs that it is unhealthy itself. While the score is high, it is slower to accuse others.
  • Dogpile. The suspicion timeout starts long and gets shorter as more members confirm the suspicion. A lone, slow accuser gets no support, so the target has time to refute.
  • Buddy system. A suspected node is told directly in the probe it receives, so it can refute at once.

HashiCorp reports more than 50 times fewer false positives under CPU exhaustion. With the new memberlist defaults, failures were found 20% faster with 20 times fewer false positives. 7

After detection

Detection is only half of the story. The action you take next often does more damage.

  • Rebalancing. Data and traffic move off the "dead" node. HashiCorp notes that false accusations move traffic away from healthy members and cause needless data rebalancing. 7
  • Flapping. The node comes back, then is removed again. GitHub's role moved away and then back on one day. 1
  • Cascading failure. Moving work to the rest of the cluster adds load. In 2011, AWS EBS nodes that lost contact assumed their peers had failed. 8 They all searched for space for new copies at once. This "re-mirroring storm" left about 13% of volumes in one zone stuck. 8

Removing a slow node is not free. The work it held lands on the nodes that are left.

Section 4 of 8

Trade-offs

OptionDetects a crash fast?Few false positives?Use it when
Fixed timeout, shortYes No Pauses and slow links trip it.Cheap actions, such as skipping a server for a few seconds.
Fixed timeout, longNo Yes Expensive actions, such as moving data.
Phi accrualYes , on a steady network.Yes It adapts to jitter.Peer-to-peer databases and actor systems such as Cassandra and Akka.
SWIM gossip with LifeguardYes Time does not grow with cluster size.Yes Indirect probes and suspicion help.Large clusters that need a shared member list, such as Consul.
A human decidesNo Yes Rare, risky moves, such as failing over a primary database.
Section 5 of 8

At work: how a senior uses this

  • Ask: "What does this cluster do when it marks a node dead, and what does a wrong guess cost?" Size the timeout to the cost of the action.
  • Use different thresholds for different actions. The phi paper's example: stop sending new work at a low level, and remove the worker only at a high one. 2
  • Know your longest normal pause: garbage collection, a big compaction, a slow disk. Your timeout must be longer.
  • Rate-limit removals. If many nodes "die" at once, suspect the network or the detector first.
  • When you see false positives, find the cause before you raise the threshold. Akka lists long GC pauses, overload and tight CPU limits. 3
  • Plan the rebalance. Check that the remaining nodes can take the extra load.
  • Make removal and rejoin cheap and gradual, so flapping does not move all the data each time.
Section 6 of 8

With AI

What to ask the agent

"Read our cluster config. List every failure detection setting: heartbeat interval, timeouts, phi threshold, suspicion multiplier. For each, explain what action it triggers."

"Our Cassandra nodes are marked down during GC pauses. Show me how to confirm this from the logs, and compare raising the phi threshold with fixing the pauses."

"Write a test that pauses one node for 10 seconds in our 5-node cluster. Show what moves, how long it takes, and what happens when the node returns."

What to check yourself

  • The agent did not raise every timeout without saying what gets slower. Longer detection means a dead node gets traffic for longer.
  • The proposed timeout is longer than your real worst pauses, taken from metrics, not guesses.
  • Automatic actions after detection have a limit, such as "remove at most one node per 10 minutes".
  • Any code that counts members handles a node that is "suspect", not only "alive" or "dead".
Section 7 of 8

Check yourself

1. Your failure detector uses a 2-second timeout. A healthy node has a 3-second garbage collection pause. What happens?

Show answer

The node is marked dead, even though it is healthy. This is a false positive. From the outside, a pause looks the same as a crash. Any silence longer than the timeout is treated as a failure.

2. What does a phi accrual failure detector give you instead of "alive" or "dead"?

Show answer

A suspicion level that grows the longer a heartbeat is late, compared with past heartbeat gaps. Phi is a score on a scale. Each application picks its own threshold, for example 8 in Akka and Cassandra by default.

3. In SWIM, node A gets no ack from node B. What does A do next?

Show answer

It asks a few other members to ping B for it. The indirect ping-req goes over other network paths. It stops one congested link from getting a healthy node removed.

4. Lifeguard adds "local health" to SWIM. What problem does that solve?

Show answer

A slow or overloaded node wrongly accuses healthy nodes of being dead. If a node is slow itself, its missed acks are probably its own fault. Lifeguard makes such a node wait longer before it accuses others.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 8 sources and related lessons
  1. Jesse Newland, “GitHub availability this week”, The GitHub Blog (September 2012) (opens in a new tab)
    The official write-up. Health checks failed on a busy MySQL primary, the cluster failed over to a cold server, and then failed back.
  2. Naohiro Hayashibara, Xavier Défago, Rami Yared, Takuya Katayama, “The ϕ Accrual Failure Detector”, JAIST Research Report IS-RR-2004-010 (May 2004) (opens in a new tab)
    The original paper. A suspicion level on a scale instead of yes or no, and what each value of phi means.
  3. Akka documentation, “Phi Accrual Failure Detector” (opens in a new tab)
    A short, practical explanation of phi with its formula, the default threshold and advice for cloud networks.
  4. Apache Cassandra documentation, “cassandra.yaml file configuration” (opens in a new tab)
    The phi_convict_threshold setting and its default.
  5. Abhinandan Das, Indranil Gupta, Ashish Motivala, “SWIM: Scalable Weakly-consistent Infection-style Process Group Membership Protocol”, Proc. International Conference on Dependable Systems and Networks (DSN 2002) (opens in a new tab)
    The SWIM paper. Random probes, indirect probes, suspicion, incarnation numbers and gossip on top of pings.
  6. Armon Dadgar, James Phillips, Jon Currey, “Lifeguard: Local Health Awareness for More Accurate Failure Detection”, arXiv:1707.00788 (2017) (opens in a new tab)
    Why slow message processing makes SWIM mark healthy members as failed, and the idea of local health.
  7. Jon Currey, “Making Gossip More Robust with Lifeguard”, HashiCorp blog (July 2017) (opens in a new tab)
    A plain summary of the three Lifeguard changes in memberlist, with results.
  8. Amazon Web Services, “Summary of the Amazon EC2 and Amazon RDS Service Disruption in the US East Region” (April 2011) (opens in a new tab)
    The postmortem of the EBS "re-mirroring storm", where nodes that lost contact assumed their peers had failed.

Real incident: GitHub, 10 Sept 2012: GitHub outage: health checks failed a busy database over, then back

Related: Why distributed systems are hard · Load balancing · Consensus and Raft · Leader election and leases · Sharding and consistent hashing · Circuit breakers, bulkheads and fallbacks

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper