Zum Hauptinhalt springen

Is It Dead or Just Slow? Failure Detection in a Cluster

· 10 Minuten Lesezeit
Clustron Team
Engineering für verteilte Systeme

Every cluster runs a background question it can never stop asking: which of my nodes are alive right now? On the surface this looks like bookkeeping — keep a list, mark each entry up or down. Underneath, it is one of the genuinely hard problems in distributed systems, because over an asynchronous network the question has no certain answer. A node that has crashed sends nothing. A node that is alive but stuck in a garbage-collection pause, or sitting behind a momentarily congested switch, or on the far side of a brief network drop, also sends nothing. From the outside, a dead node and a slow one are the same thing: silence. The detector's entire job is to decide what a stretch of silence means, and the evidence can never settle it.

Because certainty is unavailable, failure detection is a bet placed under a deadline. Wait long enough and the silence will eventually resolve — the node comes back, or it never does — but "long enough" trends toward forever, and a cluster cannot leave a dead node's data unowned while it waits to be sure. Act quickly instead and you will sometimes be wrong in the other direction: you declare a node dead that was only slow, and the cluster spends real effort reacting to a death that did not happen. Every detector in existence picks a point on this line, and the point it picks shows up in production as one of two symptoms — stale ownership when it waits too long, or needless churn when it fires too soon.

The useful insight is that you do not escape this by building a smarter detector. The problem is provably undecidable in the general case; there is no timeout and no algorithm that is both always fast and never wrong. What you can do is make the detector's inevitable mistakes cheap — fast to detect, cheap to react to, and safe to undo. This post walks through how: adaptive timeouts, a suspicion state between alive and dead, confirmation before irreversible action, and why the rest of the system has to be built so that a wrong guess costs a little churn instead of a lost write.

Silence is the only signal​

The mechanism underneath almost every detector is the heartbeat. Each node periodically emits a small "still here" message, and its peers watch for the beats to keep arriving. The signal the detector actually works with is therefore a negative one — the absence of an expected beat — and absence is exactly what cannot be interpreted with confidence. A missing beat might mean the sender is gone; it might mean the beat is sitting in a switch buffer; it might mean the sender paused for a full second collecting garbage and will resume as if nothing happened. The detector has to convert "I have not heard from you in T" into the verdict "you are dead," and every hard choice lives in how it picks T and what it does the instant T is crossed.

The timeout you pick is a confession​

Make T short and detection is fast: a crashed node is noticed almost immediately and the cluster reacts while clients have barely begun to time out. But a short T is tripped by the ordinary, survivable pauses — the GC stall, the 300ms network hiccup — and each time it trips on a live node you have a false positive. A false positive is not a harmless re-check; it fires a failover, an ownership transfer, a replica promotion, and a wave of clients re-routing to the new owner, all of it expensive, and all of it wasted because the node was never dead. Worse, for a moment you may have two nodes that each believe they own the same data.

Make T long and the false positives nearly vanish — no ordinary pause lasts that long — but now when a node actually dies, its keys sit unowned or stale for the entire timeout, and every client that needs them hangs or gets errors until the deadline finally expires. There is no single value of T that is both quick to catch a real death and patient enough to ignore a survivable pause, for the same reason a lock's lease cannot be both: the pauses you must not mistake for death have no upper bound.

Adaptive detection: judge against recent history​

The way past a fixed T is to stop using one. Instead of a hard deadline, keep a sliding window of each peer's recent heartbeat intervals and compute a suspicion level that rises continuously as the next beat becomes overdue — scaled by how punctual that particular peer has been. A node on a steady link that misses a beat by a hair is barely suspected; a node that has been metronome-regular and then goes completely silent is suspected quickly, because the silence is wildly out of character. The effective timeout adapts to the peer and the path on its own: a jittery cross-rack link earns more slack than a quiet in-rack one, with no constant to hand-tune per link.

// Per peer, keep a sliding window of recent heartbeat intervals.
window.Record(now - lastBeat) // on each heartbeat received

// Suspicion grows with how overdue the next beat is, scaled by the
// peer's OWN observed mean and variance — not a fixed threshold T.
phi = suspicion(elapsedSinceLastBeat, window.Mean(), window.StdDev())

if (phi > SUSPECT) markSuspect(peer) // cheap, reversible: stop new work
if (phi > CONFIRM) beginFailover(peer) // expensive, irreversible step

Suspect is not dead​

Notice the two thresholds in that sketch — they matter as much as the adaptive curve. Collapsing the world into alive and dead forces the detector to couple a cheap decision to an expensive one. Splitting out a suspect state decouples them. When suspicion first crosses SUSPECT, take only the cheap, reversible action: stop routing new writes to that node. Do not promote a replica yet. Confirm first — either let suspicion climb past the higher CONFIRM threshold, or ask a different node to probe the suspect directly with an indirect ping. A node that looks gone from one vantage point but answers another is not dead at all; the link between those two peers is broken, which is a transport problem and not a membership change. That indirect probe is what separates "I cannot reach you" from "the cluster agrees you are gone," and it turns the most common transient — one flaky path — back into what it actually is instead of a reason to reshuffle ownership.

suspicion φCONFIRMSUSPECTtime →heartbeats arrive — φ stays lowGC blip: φ rises……beat resumes, φ dropscross SUSPECT → stop new workcross CONFIRM → failoverno more beats — the node is truly gone

Why a detector is allowed to be wrong​

Even with an adaptive curve, two thresholds, and indirect probes, the detector will still be wrong sometimes — it fires late on a real death, or fires on a pause that would have resolved — because the underlying problem does not have a correct solution over an async network. The escape is not a better detector; it is a system that stays correct when the detector errs. Suppose the detector declares an owner dead and promotes a replica, and the old owner was only paused and comes back. Correctness must not depend on the old owner having noticed it was replaced — and it does not, if writes carry a fencing token: the promoted owner holds a higher token, so the resurrected owner's writes are rejected the moment they reach the resource. Failure detection decides when to act; fencing makes acting safe regardless of whether the detector guessed right. That is what shrinks the detector's job from the impossible "be correct" down to the achievable "be timely and cheap to undo."

Wrap-up​

"Is it dead or just slow?" has no certain answer, because silence is the only evidence and two different failures produce the same silence. A fixed timeout forces you to choose, up front, between stale ownership and needless churn, and neither choice is good at both ends. An adaptive detector judges each peer against its own recent behavior, so the effective deadline fits the link instead of a guessed constant. A suspicion state between alive and dead keeps the cheap, reversible reaction — stop sending work — separate from the expensive, irreversible one — promote a replica — and an indirect probe tells a dead node apart from a broken link. But the move that matters most is to stop demanding the detector be right. Build fencing into the writes and reversibility into the reaction, and a wrong guess costs a moment of churn instead of a lost write — which is the only arrangement that lets the detector be fast without being dangerous.