AlgoViz

Fault tolerance and failure detection

medium 24 min

A cluster must notice that a machine is gone, keep serving without it, and bring it up to date when it returns.

See it run

Notice a silent node, work around it, and repair it when it returns.

Operations

Heartbeat

Node C goes silent. The others suspect it, confirm it, tell everybody and route around it.

Step 1 of 5

Normal operation

The storeClientCoordinatorNode AaliveNode BaliveNode Calive

Every node sends heartbeats, and all are alive.

Step 1: Normal operation

def check(now):    for node in peers:        silent = now - last_seen[node]        if silent > TIMEOUT and state[node] == ALIVE:            state[node] = SUSPECT        if state[node] == SUSPECT and not others_reach(node):            state[node] = DOWN            gossip(node, DOWN)
Time
Interval + timeout
Costs
Small messages
All to all, 1,000 nodes
999,000 per interval

Suspect first. Avoiding a node is cheap, moving its data is not.

In the real world

The same fault tolerance and failure detection doing real jobs. Pick one and step through it.

Node C stops for 12 seconds to clean up its memory. The timeout is 10 seconds.

Step 1 of 4

Pause begins

The storeClientCoordinatorNode AaliveNode BaliveNode Cpaused

C is alive but does nothing, not even sending heartbeats.

Step 1: Pause begins

Common mistakes

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

  • Acting on one missed beat

    critical

    A lost packet or a short pause starts an expensive rebuild and loads the healthy nodes.

    Wrong
    if missed >= 1: rebuild(node)
    Right
    if missed >= 5: suspect(node)if gone_for(hours=12): ask_operator(node)
  • Relying on hints alone

    critical

    Hints expire, and the node that keeps them can fail too.

    Wrong
    repair = [hints]
    Right
    repair = [hints, read_repair, merkle_sync]
  • No limit on hints

    major

    A long outage fills the disk of a healthy node, and replay floods the returning one.

    Wrong
    hints.append(write)
    Right
    if hint_age < WINDOW and hint_bytes < MAX:    hints.append(write)
  • Repairing too rarely

    major

    After the grace time, the record of a deletion is dropped. A node that missed it brings the data back.

    Wrong
    repair every 30 days, grace 10 days
    Right
    repair every 5 days, grace 10 days

Interview tips

  • How to explain it

    • Notice, continue, repair.
    • Silence is all you see.
    • Suspect first, confirm with others.
  • GHRMA

    • Gossip and heartbeat notice.
    • Replicas keep the data.
    • Merkle trees and anti-entropy repair.
  • Good habits

    • Timeouts from measured delays.
    • Different limits for different reactions.
    • Regular repair and failure tests.
  • Be careful with

    • Pauses that look like crashes.
    • Splits seen from both sides.
    • Automatic rebuilds.