SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
  • Challenges of Distribution
  • Failure Types: Crash vs Byzantine
  • Network Partitions
  • Split Brain Problem
  • Heartbeats
  • Failure Detectors
  • Handling Failures
  • Consistency Models
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Distributed Systems/Distributed System Fundamentals

Failure Detectors

The part that guesses which machines are dead, and why every guess can be wrong.

⏱ 13 min readIntermediateMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A failure detector is the part of a system that guesses which machines have failed. It is only a guess, because in an asynchronous network you cannot tell a dead machine from a slow one.

  • Completeness: a machine that really crashed is eventually suspected.
  • Accuracy: a healthy machine is not suspected (or, at least, not forever).
  • You cannot get both perfectly, so real detectors pick a balance: timeouts, adaptive (phi accrual) and gossip-style (SWIM) detectors.

02Concept: What is it?

The Heartbeats topic shows how machines send β€œI am alive” signals. This topic is about the layer above: the rules for deciding from those signals who is dead, and what we can promise about those decisions.

In 1996, Chandra and Toueg described failure detectors by two properties. Completeness is about missing nothing: every crashed node is suspected by the others. Accuracy is about not crying wolf: healthy nodes are not suspected.

PropertyPlain meaningFails when
Strong completenessEvery healthy node eventually suspects every crashed nodeSome healthy node never notices a crash
Weak completenessAt least one healthy node eventually suspects each crashed nodeNobody notices a crash
Strong accuracyNo healthy node is ever suspectedA slow node is wrongly accused
Eventual accuracyAfter some unknown time, healthy nodes stop being suspectedThe accusations never stop
A detector can be wrong in two ways
πŸ”No reply for 3 secondswhat does it mean?
→↓maybe
πŸ’₯Node crashedcorrect to suspect
→↓or maybe
🐌Node slow or cut offfalse suspicion
Dead and slow look the same from the outside. All the detector sees is silence.
🧠The impossibility behind it
The FLP result (1985) says that in a fully asynchronous system, no algorithm can guarantee agreement if even one node may crash, because you cannot tell a crash from a delay. Failure detectors are the standard way out: add a small amount of timing guesswork and agreement becomes possible again.

03Real-Life Example

🍡The Quiet Neighbour
You have not seen your neighbour for three days. Are they away, ill or just busy? You can wait longer (slower to react, fewer false worries), or knock now (faster, but you might wake them for nothing). A good plan: knock, then ask other neighbours "have you seen them?" before calling for help.
Neighbour story
Failure detector
Days without seeing them
Time since the last heartbeat
How long you wait before worrying
The timeout
Knocking too early for nothing
A false suspicion (accuracy problem)
Not noticing for a month
A missed failure (completeness problem)
Learning their usual routine
Adaptive detector (phi accrual)
Asking other neighbours
Indirect probe (SWIM)
Everyone telling their friends the news
Gossip of suspicions
Ask before you accuse (SWIM-style)
πŸ–₯️A pings Dno reply
→↓ask helper
πŸ–₯️B pings D for AD answers B
→↓relay: alive
βœ…A drops the suspicionthe A to D link was bad

04Why Do We Need It?

πŸ”Failover
Moving work from a dead node to a live one starts with deciding that it is dead.
πŸ‘‘Leader election
Followers start an election when they suspect the leader.
🧭Membership
A cluster must know who is currently in it to route and replicate correctly.
πŸ—³οΈConsensus progress
Detectors are what let Paxos and Raft keep making progress despite FLP.
βš–οΈBalance
Too jumpy causes pointless failovers. Too slow leaves users waiting on a dead node.
πŸ“ˆScale
At thousands of nodes, how you detect matters: all-to-all pings do not scale.
A failure detector turns silence into an action, so being wrong in either direction has a cost you can choose.

05Where Do We Use It?

πŸ””Cassandra
Uses a phi accrual detector over gossip to decide which nodes to avoid.
πŸ•ΈοΈConsul and Serf
Use SWIM (Lifeguard) for membership and failure detection.
πŸ—³οΈRaft and ZooKeeper
An election timeout acts as a simple failure detector for the leader.
🎭Akka Cluster
Phi accrual detector between members.
☸️Kubernetes
Node controllers mark a node NotReady after a grace period of missed heartbeats.
🧰Load balancers
Health checks are a detector with a threshold, such as 3 fails in a row.

06Types / Parts / How It Works

Classes of detectors

ClassCompletenessAccuracyWhat it means in practice
Perfect (P)StrongStrongNever wrong. Needs a synchronous network with known time limits.
Eventually perfect (β—‡P)StrongEventualMay be wrong for a while, then correct. What real systems aim for.
Strong (S)StrongWeak (one healthy node is never suspected)Enough for consensus.
Eventually strong (β—‡S)StrongEventually weakThe weakest class that still lets consensus work. Raft and Paxos live here.

How detectors are built

StyleHow it worksGood atWeak at
Fixed timeoutSuspect after N seconds of silenceSimple, predictableOne number cannot suit every link
Adaptive (phi accrual)Learns normal timing and outputs a suspicion levelSlow links, changing loadMore tuning knobs
All-to-all heartbeatsEveryone pings everyoneFast detectionLoad grows with the square of cluster size
SWIM-stylePing one random node per round, with indirect probes through othersFixed load per node at any scaleSlightly slower to spread news
Gossip heartbeatNodes share heartbeat counters with random peersScales, no central pointDetection time grows slowly with size
SWIM in one round
1. Direct ping
πŸ–₯️A pings D
↓no ack
2. Indirect probes
πŸ–₯️A asks k helpersplease ping D
↓still no ack
3. Suspect, then confirm
⏳Mark D suspectD has time to refute it
↓no refutation
πŸ’€Declare D dead
Each node does a small, fixed amount of work per round, no matter how big the cluster is.
Normal ping Second opinion Suspicion
VisualizerOne crash, one slow node: which detector copes?Node C really crashes at 24 s. Node D is always alive but has a slow link. Switch the detector style and drag the timeout to see the trade between completeness (found the crash) and accuracy (never accused D).
Detector style
One number for every node. Simple, but a slow node looks dead.
C: really crashes at 24 s
A's opinion of C (green trusts, amber suspects: correct)
D: always alive, slow link
A's opinion of D (red = false suspicion)
0 s20 s40 s
Completeness
yes
every crash found
Accuracy
yes
no healthy node accused
False suspicions
0
about the healthy D
Crash found after
1 s
detection time
Complete and accurate on this run: the crash of C was found after 1 s and the healthy node D was never accused. Real networks are not this polite, so no detector can promise both forever.

A simplified model with a fixed delay pattern (no random numbers). The SWIM-style detector asks a helper to probe D before accusing it, so a slow link alone does not cause a false suspicion. C is really dead, so the helper cannot reach it either.

07How to Use It / Steps / Implementation

Designing and tuning a detector

  1. 1
    Decide the cost of each mistake
    A false suspicion may trigger a failover. A missed crash leaves users waiting. Compare the two costs first.
  2. 2
    Start with heartbeats
    Send small regular messages. See the Heartbeats topic for the interval and timeout trade-off.
  3. 3
    Prefer adaptive over fixed
    Measure real gaps between beats and let the threshold follow them (phi accrual).
  4. 4
    Ask a second opinion
    Before declaring a node dead, have other nodes try to reach it (indirect probes).
  5. 5
    Use a suspect state
    Mark nodes suspect first, give them time to say β€œI am alive”, and only then declare dead.
  6. 6
    Let a node refute
    A healthy node that hears it is suspected can send an incarnation number higher than the rumour, and clear itself.
  7. 7
    Make actions safe when wrong
    Assume the detector will be wrong sometimes. Use fencing tokens and idempotent steps so a false failover does no harm.
πŸ’‘Detectors do not decide, they advise
Treat "suspected dead" as a hint. The safe action (such as taking a lock or promoting a leader) should still be guarded by a quorum or a fencing token.

08Key Terms to Know

TermMeaning in easy words
Failure detectorA component that reports which nodes it suspects have failed
CompletenessCrashed nodes are eventually suspected
AccuracyHealthy nodes are not suspected
Strong / weak completenessEvery healthy node vs at least one healthy node suspects each crash
Eventually perfect (β—‡P)May be wrong for a while, then becomes right for good
SuspectBelieved to be dead, but not yet confirmed
False positiveA healthy node wrongly suspected
Phi accrualA detector that outputs a suspicion level learned from past timing
SWIMScalable gossip-style membership protocol with indirect probes
Indirect probeAsking other nodes to ping a suspected node for you
Incarnation numberA counter a node raises to prove it is alive and overrule old suspicions
FLP impossibilityNo deterministic consensus is guaranteed in a fully asynchronous system with one crash

09Pros, Cons and Trade-offs

βœ… Pros
  • Lets a cluster react to failures without a human
  • Makes consensus possible in practice
  • Adaptive and SWIM-style detectors scale well
  • A suspect state reduces needless failovers
  • Simple versions are easy to build and test
⚠️ Cons
  • Never perfect: dead and slow look the same
  • Short timeouts cause false alarms and flapping
  • Long timeouts delay recovery
  • Different nodes may disagree about who is dead
  • Wrong suspicions can trigger expensive or unsafe actions

Trade-offs

ChoiceWe gainWe lose
Short timeoutFast failoverMore false suspicions
Long timeoutFew false alarmsSlow to react to real crashes
All-to-all heartbeatsQuick, directCost grows as n squared
SWIM / gossipConstant load per nodeSlower, fuzzier news
Indirect probesFewer false positives from one bad linkExtra messages
Suspect stateTime to refuteSlower final decision

10Common Problems and Mistakes

Common mistakes

  1. Trusting the detector as truth. A suspected node may be alive and still writing. Guard actions with quorums and fencing tokens.
  2. One timeout for every link. Same-rack and cross-region latencies are very different.
  3. No suspect stage. Going straight from silence to dead causes flapping.
  4. Everyone pinging everyone. Heartbeat traffic overwhelms a big cluster.
  5. Ignoring pauses on the detector itself. If the checking node pauses, it wakes up seeing "late" heartbeats from everybody.
  6. Declaring dead on one bad link. A single broken path should not kill a healthy node. Ask others.

Things to watch

🌊Flapping
A node goes dead, alive, dead, alive. Add hysteresis, or require several misses.
🧱Detector pauses
A GC pause on the detector looks like every other node failing at once.
πŸ—ΊοΈSplit views
Two parts of the cluster can have different opinions. This is the root of split brain.
⏱️Clock jumps
Time-based detectors need a monotonic clock, not the wall clock.

11Real-World Examples

πŸ“„Chandra and Toueg (1996)
Defined the classes of failure detectors and showed which are enough for consensus.
🏺Cassandra
Phi accrual on top of gossip. The phi threshold is a setting you can tune per environment.
🧭HashiCorp Serf and Consul
SWIM with Lifeguard extensions, so a slow checking node does not accuse healthy ones.
⏲️Raft election timeout
A randomised timeout is the detector. If no leader message arrives, the follower stands for election.
☸️Kubernetes node lifecycle
A node missing status updates becomes Unknown, then its pods are evicted after a grace period.
🌐Load balancer health checks
Mark a backend unhealthy after several failed checks and healthy after several passes.
Mini case: pause makes a healthy node look dead
πŸ‘‘Leader pauses 10 slong GC
→↓followers time out
πŸ†•New leader electedterm 8
→↓old leader wakes (term 7)
πŸ›‘οΈRejected as stalesteps down
A good system makes the false failover harmless.

12Related Topics to Read Next

Heartbeats→

The signals a failure detector is built from.

Failure Types: Crash vs Byzantine→

What kinds of failure we are trying to detect.

Split Brain Problem→

What happens when two parts disagree about who is alive.

Leader Election→

Elections start when a leader is suspected.

Gossip Protocol→

The spreading method behind SWIM and many detectors.

Consensus Algorithms→

Why detectors are needed to get around FLP.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”Detector: guesses who is dead from silence.
  • βœ”Completeness: every crash is eventually suspected.
  • βœ”Accuracy: healthy nodes are not suspected.
  • βœ”Impossible to be perfect: dead and slow look the same (FLP).
  • βœ”Aim: eventually perfect (β—‡P) is enough for consensus.
  • βœ”Styles: fixed timeout, phi accrual, SWIM with indirect probes, gossip.
  • βœ”Be safe when wrong: suspect first, ask others, guard with fencing tokens.
  • βœ”One line: β€œSilence is a clue, not proof.”
← Previous
Heartbeats
Next β†’
Handling Failures