AlgoViz

Failure models

medium 30 min

A failure model is a list of the ways a machine or message may go wrong that your design promises to survive.

Video lesson · Chapter 1 of 5

Silence is evidence, not a diagnosis

0:00 / 3:48

Stop, stall or lie in 75 seconds

1:15Reel coming soon

Theory

Read or listen first. About 2 min.

What it is

When many machines work together, some of them fail while the rest go on. A failure model describes how a part may fail: it may stop for good, stop and come back, lose messages, answer too late, or answer wrongly.

The model is a promise about your assumptions. A design that survives machines that stop may still break when a machine sends wrong data. So the first question about any reliable system is: reliable against what?

Why it exists

No design survives everything, and each extra kind of failure costs something. To go on after one machine stops, three machines with majority voting are enough. To go on while one machine lies, you need four and more rounds of messages.

The model also decides how you find out. A stopped machine and a slow one look the same from outside: both are silent. Every detector is a guess with a time limit, and it can be wrong in both directions.

A short history

  1. 1982

    Lamport, Shostak and Pease publish "The Byzantine Generals Problem" and give arbitrary failures their name.

  2. 1985

    Fischer, Lynch and Paterson show that in an asynchronous system no deterministic protocol can guarantee that consensus finishes if even one process may fail. The result is called FLP.

  3. 1996

    Chandra and Toueg publish unreliable failure detectors: how much guessing is enough to reach consensus.

  4. 1999

    Castro and Liskov present Practical Byzantine Fault Tolerance, PBFT, at OSDI.

  5. 2018

    The HotStuff paper describes a leader-based Byzantine protocol, presented for blockchains.

Words to know

Fault
Something is wrong in one part, such as a broken disk.
Failure
The part, or the system, no longer does what it promised.
Crash-stop
A process halts and never comes back.
Crash-recovery
A process halts and may return with what it stored on disk.
Omission
A message is not sent or not received.
Timing failure
The answer is right but too late.
Byzantine
Any behaviour at all, including lies.
Failure detector
A part that guesses, from silence, who has failed.
Quorum
How many nodes must agree before the system acts.

How it works

Step through the idea, or press Play.

Step 1 of 3

List what may go wrong. Stop, return, lose messages, be slow, lie

Understand it

Start here

The helper robots

A workshop has three helper robots that pass boxes and messages along. On a good day nobody notices them. On a bad day each robot has its own way of going wrong, and each needs a different answer.

Five ways to be unhelpful

From outside, the stopped robot, the lost note and the slow robot look alike: silence.

A game of passing notes shows the same classes: a friend goes home (crash), a note gets lost (omission), a friend is too slow (timing), or a friend changes the note (Byzantine).

The ladder

From simple to hard

ModelWhat happensExamplesAnswer
Crash-stopHalts, never returnsDead hardware, a killed processReplicas, leader election
Crash-recoveryHalts, may return with its diskRestart, out-of-memory kill, rolling updateWrite-ahead log, checkpoints
OmissionSome messages lostPacket loss, full queue, firewall ruleAcknowledge, retry, remove duplicates
TimingRight, but too lateGarbage collection pause, busy CPU, slow diskTimeouts, circuit breakers
ByzantineAnything, even liesCorrupt memory, a bug, a taken-over nodeVotes with 3f + 1 nodes, signatures
Each class contains the ones above it: a crash is an omission of everything from now on.

Each class contains the simpler ones

A design for a class further right also survives the simpler ones, at a higher price.

Crash

Stop, and stop then return

Crash-stop is the kindest failure: a process works correctly until it halts. Crash-recovery is closer to life. The process comes back, memory is gone, and the disk holds what was flushed. It may also believe it is still the leader.

Handling a crash

  1. 1

    Heartbeats

    Each node sends a small message at a fixed pace.

  2. 2

    Timeout

    Too long without one: suspect the node.

  3. 3

    Election

    The rest agree on a new leader with a higher term number.

  4. 4

    Recovery

    The returning node replays its log, sees the higher term and follows.

A leader stops

Term numbers make a late old leader harmless. Raft chooses election timeouts at random, for example from 150 to 300 ms, so that two nodes seldom start at once.

Recovery

Write-ahead log

Before changing anything, write down what you are about to do and force it to disk. After a crash, replay the log. The order matters: log, fsync, then confirm. A log that was never forced to disk can vanish with the power, together with a write you already confirmed.

Python
disk = []          # survives a crashmemory = {}        # does notdef put(key, value):    disk.append((key, value))     # 1. log first (and fsync)    memory[key] = value           # 2. then change    return "ok"                   # 3. then confirmput("stock", 5)put("stock", 4)memory = {}                       # crashfor key, value in disk:           # replay    memory[key] = valueprint(memory)
Replay must be safe to repeat: writing the value 4 twice is fine, "subtract one" twice is not.
Edit and run it in your browser

Messages

Omission

Send omission

  • A buffer overflows before the network
  • A firewall blocks traffic out
  • A bug skips the send

Receive omission

  • The packet is lost on the way
  • The receive buffer is full
  • The queue overflows

Acknowledge every message, retry with growing pauses and jitter, and give each message a number so that the receiver can drop duplicates. Retrying has a trap: when the answer is lost, the work was done. Only idempotent work may be repeated blindly. More in retries.

The answer is lost

Chance that all tries are lost

P=p kp=1%,;k=3:;0.013=10−6P = p^{\,k} \qquad p=1\%,; k=3:; 0.01^3 = 10^{-6}
With independent losses. Real losses come in bursts, when a link is down every try fails, so pauses between tries matter more than their number.

Slow

Timing failures

A slow node is often worse than a dead one. It still answers health checks, still receives work, and holds the threads of everybody who waits for it. Set timeouts, stop calling it for a while with a circuit breaker, and compare nodes with each other: the one far from the rest is the sick one.

Lies

Byzantine failures

  • Different values to different nodes

    A says the box is red to one and blue to another.

  • Lying about what it received

    It claims a vote that never came.

  • Working together

    Several faulty nodes tell the same lie.

  • Being slow on purpose

    It answers just before each timeout.

The cause need not be an attacker. A bad memory chip, a bug or a wrong build can make a node say different things to different peers. Inside one company most systems accept that risk and use checksums instead of full Byzantine agreement. Between organisations that do not trust each other, such as in a blockchain, it is the normal model.

Why 3f + 1 nodes

wait for q=n−foverlap of two quorums: 2q−n=n−2f≥f+1;⇒;n≥3f+1\text{wait for } q = n - f \qquad \text{overlap of two quorums: } 2q - n = n - 2f \ge f + 1 ;\Rightarrow; n \ge 3f + 1
You cannot wait for more than n - f answers, since f may never come. Two such quorums must share at least one honest node, so the overlap must exceed f. For f = 1: 4 nodes with quorums of 3. For f = 2: 7 nodes with quorums of 5.

Nodes needed to survive f failures

fCrash, data still readableCrash, majority votingByzantine voting
1234
2357
34710
The columns are f + 1, 2f + 1 and 3f + 1. The last assumes an asynchronous or partly synchronous network.

One liar among four

Four nodes. Node 2 is faulty and tells node 1 A, node 3 B and node 4 A. The honest nodes 1, 3 and 4 exchange what they heard and all settle on A.
Node 3 heard B, but after the honest nodes compare notes, A has the votes. With only three nodes, two honest ones could not tell who lied.

PBFT, HotStuff and Tendermint, now developed as CometBFT, reach agreement with such quorums, several rounds and signatures. A signature proves who sent a message and stops others from changing it. It does not stop a node from signing two different messages, so the votes are still needed.

Detection

Guessing from silence

MethodHowGoodWeak
Heartbeat with timeoutA node sends every second; silent for 5 s: suspect; 10 s: failedSimpleOne fixed limit for all networks
Phi accrualTurns the time since the last heartbeat into a level of suspicionAdapts to the network; callers choose the limitNeeds history to learn from
SWIMProbe a random member; if silent, ask others to probe itConstant load for each member; fewer false alarmsNews spreads by gossip, so not at once
The phi value has no upper limit: it keeps rising while the silence lasts. Cassandra's configuration has a threshold for it, and Consul's gossip builds on SWIM.

An indirect probe

Node A probes node B directly and gets no answer. A asks nodes C and D to probe B. Both reach B, so B is alive and only the path from A to B is broken.
One silent path is not a dead node. If C and D also hear nothing, A marks B as suspect, and as failed if nobody objects in time.

Real settings

SystemSettingDefault in its documents
etcd 3.5Heartbeat interval100 ms
etcd 3.5Election timeout1,000 ms
KubernetesLease renewed by the kubeletevery 10 s
KubernetesSilence before a node is unknown50 s
KubernetesWait before evicting its pods5 minutes
A shorter limit finds failures sooner and raises more false alarms. Defaults change between versions.

Choosing the timeout

T=k×intervalP(false alarm)≈p kinterval=1 s,;k=5,;p=1%:;T=5 s,;10−10T = k \times \text{interval} \qquad P(\text{false alarm}) \approx p^{\,k} \qquad \text{interval}=1\text{ s},; k=5,; p=1\%:; T=5\text{ s},; 10^{-10}
With independent losses, which is optimistic. A pause of the node itself, such as 8 seconds of garbage collection, causes a false alarm however good the network is.

Silence: what now?

Fencing means that the old node can no longer write, even if it was only slow.

Do it well

Working rules

Do

  • State the model and how many failures at once
  • Heartbeats with limits that fit the network
  • A log that is forced to disk
  • Retries with backoff, jitter and a limit
  • Signatures where nodes are not trusted
  • Break things on purpose, regularly

Do not

  • Assume that nodes are always reachable
  • Set limits so tight that healthy nodes are killed
  • Retry for ever
  • Trust unverified messages across a trust border
  • Ignore half-broken nodes

One line to remember: design for the failures you expect, and watch for the ones you do not. How to keep serving while parts fail is the subject of resilience.

Summary

The whole topic in one minute.

Failures form a ladder: crash-stop, crash-recovery, omission, timing, Byzantine. Higher steps include more bad behaviour and cost more to survive: 2f + 1 nodes for f crashes with majority voting, 3f + 1 for f liars.

Detection is guessing from silence. Heartbeats with timeouts are simple, accrual detectors give a level of suspicion, and SWIM spreads the work over the group. A slow node cannot be told from a dead one, so make a wrong guess harmless with fencing, idempotent work and retries with limits.

  • A failure model says what your design survives.
  • Crash-stop, crash-recovery, omission, timing, Byzantine: each is harder.
  • 2f + 1 nodes for f crashes with voting, 3f + 1 for f liars.
  • Slow and dead look the same; every detector guesses.
  • Log, force to disk, then confirm.
  • Make wrong guesses harmless with terms, fencing and idempotent work.

Sources