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.

See it run

Watch a node stop, come back, lose messages, slow down and lie, and what the others do about it.

Operations

Crash-stop

A node halts. The rest notice and elect a new leader.

Step 1 of 5

Normal operation

Node 1followerNode 2leader, term 1Node 3follower

Node 2 leads and sends heartbeats.

Step 1: Normal operation

if now - last_heartbeat[leader] > timeout:    term += 1    votes = ask_all("vote for me", term)    if votes >= members // 2 + 1:        become_leader(term)
Nodes needed
2f + 1
Tool
Heartbeats
Data only
f + 1 copies

Count votes against all members, not only against those that answer.

In the real world

The same failure models doing real jobs. Pick one and step through it.

The leader is frozen for 20 seconds. A new one is elected. Then the old one returns.

Step 1 of 4

Leader with token 1

write, 1Old leadertoken 1New leaderstandbyStoragehighest: 1

It writes to storage with token 1.

Step 1: Leader with token 1

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Promoting without fencing

    critical

    The silent primary may only be slow. Two primaries then accept writes.

    Wrong
    if timeout(primary):    promote(standby)
    Right
    if majority_agrees_dead(primary):    token = next_token()    fence(primary)    promote(standby, token)
  • A log without fsync

    critical

    The data sits in the operating system's cache and goes with the power.

    Wrong
    f.write(entry)return "ok"
    Right
    f.write(entry); f.flush()os.fsync(f.fileno())return "ok"
  • Retrying for ever

    major

    Every client repeats into a system that is already down, and it cannot recover.

    Wrong
    while True:    try_again()
    Right
    for i in range(4):    try_again()    sleep(random() * min(cap, 2 ** i))
  • Treating never seen as failed

    minor

    A node that is just joining would be removed before its first heartbeat.

    Wrong
    return last.get(node) is None or late(node)
    Right
    if node not in last:    return "unknown"

Interview tips

  • How to explain it

    • Say what may go wrong and how many at once.
    • Each step of the ladder costs more.
    • Detection is a guess.
  • Memory trick: COOTB

    • Crash-stop, crash-recOvery.
    • Omission, Timing.
    • Byzantine.
  • Numbers to know

    • f + 1 copies to keep data.
    • 2f + 1 to vote after crashes.
    • 3f + 1 to vote among liars.
  • Watch out for

    • Slow nodes.
    • Old leaders that wake up.
    • Lost answers.