Fault tolerance and failure detection
medium 24 minA cluster must notice that a machine is gone, keep serving without it, and bring it up to date when it returns.
Video lesson · Chapter 1 of 5
One server misses its heartbeat
Is it dead or just slow?
1:20Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
Fault tolerance means that a system keeps doing its job while some of its parts are broken. In a replicated store this takes three steps: notice the failure, continue without the failed node, and repair it afterwards.
Failure detection is the first step. A node cannot look inside another node. It can only notice that messages have stopped, and silence has several causes: a crash, a slow node, a long pause or a broken link.
Why it exists
With many machines, some part is always failing. If each node fails once in three years, a cluster of 1,000 nodes sees about one failure a day. Waiting for a person to react is not a plan.
The detector has to choose between two mistakes. If it is hasty, it declares healthy nodes dead and moves work for nothing. If it is slow, requests keep going to a dead node. The tools on this page soften that choice, but none can remove it.
A short history
1979
Ralph Merkle patents the hash tree, which later becomes the tool for comparing large copies of data.
1987
Alan Demers and colleagues describe epidemic algorithms for keeping database copies in step: the root of gossip and anti-entropy.
1996
Tushar Chandra and Sam Toueg publish their work on unreliable failure detectors: detectors that may be wrong can still be useful.
2004
Naohiro Hayashibara and colleagues describe the phi accrual failure detector, which reports a level of suspicion instead of yes or no.
2007
The Dynamo paper combines gossip membership, sloppy quorums, hinted handoff and Merkle trees in one store.
Words to know
- Heartbeat
- A small message sent at a fixed interval that says: I am alive.
- Gossip
- Each node regularly exchanges what it knows with a random other node.
- Suspicion
- The state between alive and declared failed.
- Sloppy quorum
- A quorum that may use the next healthy nodes when the normal replicas are down.
- Hint
- A stored write with a note about the node that should have received it.
- Anti-entropy
- Comparing copies in the background and repairing the differences.
- Merkle tree
- A tree of hashes in which each parent is the hash of its children.
How it works
Step through the idea, or press Play.
Notice. Heartbeats stop, suspicion rises, others confirm
Understand it
Start here
Scouts in the forest
Imagine five scouts spread through a forest. There is no leader who counts them. Whenever two of them meet, they compare notes: whom have you heard from lately?
Nobody can see Max. They can only compare what they have heard.
A team of firefighters works the same way. If one is sick, the others cover the area. They check on each other all the time, and the colleague who returns is told what happened meanwhile.
The problem
What can fail, and what helps
| Failure | What it looks like |
|---|---|
| Crash | The node stops and stays stopped |
| Omission | Messages get lost on the way in or out |
| Byzantine | The node answers wrongly, by a fault or on purpose |
Six mechanisms
Failure detection
Heartbeats and gossip show who is silent.
Replication
Several copies, so that one lost node loses no data.
Sloppy quorum
Write to the next healthy nodes instead of giving up.
Hinted handoff
A short-term home for writes that a node missed.
Read repair
Fix an old copy when a read finds it.
Anti-entropy
Compare copies in the background with Merkle trees.
How the copies are made is the topic of data replication.
Notice 1
Heartbeats and timeouts
A node sends a small message at a fixed interval, to its peers or to a central watcher. If none arrives within the timeout, it counts as failed. Typical starting points for a store: an interval of 1 to 5 seconds, a timeout of 3 to 10 seconds, and 2 or 3 missed beats before marking a node down. Coordination services inside one data centre often use much shorter values.
Two beats, then silence
How long until it is noticed?
Notice 2
Suspicion instead of yes or no
A fixed timeout suits one network. The phi accrual detector learns how the heartbeats of each node usually arrive and turns the current silence into a number, phi. The longer the silence compared with normal, the higher phi. Each user of the number sets its own limit: stop sending reads at a low one, move data at a high one.
Phi
| Phi | Meaning in the model | Possible reaction |
|---|---|---|
| 1 | 10% chance of being wrong | Probably alive; prefer other nodes |
| 3 | 0.1% | Stop sending new requests |
| 8 | 0.000001% | Mark the node down |
| 10 and more | Even less | Likely dead |
Spread the news
Gossip
Every T seconds, each node
- 1
Picks a random peer
Often one, sometimes a few.
- 2
Exchanges state
Membership, heartbeat counters, load. Push, pull, or both.
- 3
Merges
For each node it keeps the entry with the newer counter.
- 4
Repeats
Like a rumour, the news spreads without any centre.
One rumour, three rounds
How many rounds?
In Cassandra every node gossips once a second, and each node decides for itself who is up. In the Dynamo paper gossip spreads membership, meaning who belongs to the ring, while temporary failures are noticed locally: if B does not answer A, A uses other nodes and checks on B now and then. Adding or removing a member was made an explicit step, so that a reboot does not trigger a reshuffle.
Make sure
Ask others before you decide
If A cannot reach B, perhaps only the path between them is broken. The SWIM protocol lets A ask some other members to probe B. If one reaches it, B is alive. If none does, B becomes suspect, and it has time to object before it is declared failed. The picture of that indirect probe is in failure models; Consul's gossip names SWIM among its foundations.
From silence to action
Continue 1
Sloppy quorum
Key K normally lives on A, B and C. If A is down, a strict quorum counts only answers from A, B and C. A sloppy quorum takes the first N healthy nodes on the ring: B, C and D. D stands in for A. The store of this example is the one from inside a key-value store, and the ring is explained in consistent hashing.
Good
- Writes succeed even if several normal replicas are gone
- No waiting for timeouts of a node that is known to be down
Costs
- R + W greater than N no longer promises overlap: a read may ask A, B and C while the write sits on D
- More conflicting versions to settle
- The stand-in may fail before it hands the write over
Continue 2
Hinted handoff
Node D keeps a write for node A
{ "target_node": "node-A", "key": "user:123", "value": { "name": "Alice" }, "timestamp": 1703001234567, "ttl": 86400}| Hinted handoff | |
|---|---|
| Helps | Writes succeed during short outages |
| Helps | The returning node needs no full copy |
| Limit | No help if a node is gone for good |
| Limit | Hints use space on the stand-in, and replay adds load |
| Limit | After the time limit, hints are no longer kept; other repair must find the difference |
Repair 1
Read repair
A read asks A, B and C. A and C return version 3, B returns version 2. The client gets version 3 and B is updated. It repairs exactly the data that people use, and nothing else. How the versions are compared is the topic of versioning data.
Repair 2
Merkle trees
Two nodes hold the same million keys, or nearly so. Sending all of them to compare would be wasteful. A Merkle tree has the hash of each block of data at the leaves. Each parent is the hash of its children. If two roots are equal, the data is equal, except for an astronomically unlikely hash collision.
Find one different block of four
- 1
Compare the roots
They differ, so go deeper.
- 2
Compare H12 and H34
H12 is the same: blocks 1 and 2 are done. H34 differs.
- 3
Compare H3 and H4
H4 is the same. H3 differs.
- 4
Copy block 3
Only that block travels over the network.
Only the red path differs
What it saves
Back again
A node recovers
- 1
Detect the recovery
Its heartbeat resumes and gossip spreads the news.
- 2
Receive the hints
Other nodes deliver the writes that they kept, at a limited speed.
- 3
Run anti-entropy
Merkle trees show what is still missing, for example after expired hints.
- 4
Resume traffic
It serves requests again. Many stores let it take part at once and rely on quorums to hide its old values.
The whole life of an outage
In practice
Settings and habits
Defaults in the documents
| System | Setting | Default |
|---|---|---|
| Cassandra | Gossip | every second |
| Cassandra | phi_convict_threshold | 8 |
| Cassandra | max_hint_window | 3 hours |
| Cassandra | Grace time of tombstones | 10 days |
| Akka | Heartbeat | every second |
| Akka | Phi threshold | 8 |
Do
- Combine detectors: heartbeats, real requests and other nodes' views
- Choose timeouts from measured delays, not too short
- Limit the age and size of hints
- Run anti-entropy regularly in the background
- Watch repair backlog, hint counts and flapping nodes
Do not
- Rely on hints alone for durability
- Use very short timeouts
- Skip tests that kill, pause and cut off nodes
- Ignore the disk space of hints
- Forget that a network split looks like a crash from both sides
Summary
The whole topic in one minute.
Nodes send heartbeats, and gossip spreads who has been heard from lately. Silence raises suspicion, others confirm it, and only then is a node treated as failed. A detector can always be wrong, so the protocol that uses it must stay safe when it is.
While a node is away, sloppy quorums and hints keep writes flowing. When it returns, hints bring the recent writes, read repair fixes what people read, and Merkle trees find the rest cheaply by comparing hashes from the top down.
- Silence is all a detector sees; slow and dead look alike.
- Short timeouts raise false alarms, long ones delay the reaction.
- Gossip spreads news in about log n rounds without a centre.
- Suspect first, ask others, act on certainty that matches the cost.
- Sloppy quorums and hints keep writes going through short outages.
- Merkle trees find differences from the top down; hints alone are not enough.