Replicated state machines under FLP
When several servers must agree on the same answer despite crashes and unreliable networks, the network itself forbids any deterministic program from being both always-correct AND always-making-progress — so Raft, like every real protocol, treats correctness as non-negotiable and treats progress as something the network has to earn.
Scene 01
Replicated state machines under FLP
- Watch
- Try it
- Predict
- Capture
Suppose you run a service that has to stay up even if one or two of its servers crash. You can't trust a single machine — machines die, disks fail, networks drop packets — so you keep several copies (servers) and you need all the surviving copies to give the client the same answer. The tricky part is that the network between them is not reliable: messages get delayed, reordered, or lost, and a server that has gone silent could be either crashed or just slow. The systems-design name for the picture you're about to watch is a replicated state machine — three identical copies of a deterministic program (one whose output depends only on its inputs, never on a clock or a random number), each fed the SAME list of commands in the SAME order. That list is called a log in the systems sense: an append-only, totally ordered sequence of commands. When the same deterministic program processes the same log, every copy must end up in the same state. Watch the three commands [SET x=1, SET x=2, INC x] apply on all three servers — they converge to x = 3.
Highlighted lines are the ones running in the diagram right now.
# Each replica holds:# log — append-only, totally ordered commands# stateMachine — DETERMINISTIC: (state, cmd) -> state'# lastApplied — index of the last command fed to stateMachinedef applyLoop():while True:# block until log[lastApplied + 1] is committedentry = waitForCommitted(log, lastApplied + 1)stateMachine.apply(entry.command)lastApplied += 1# invariant: same log prefix, same lastApplied,# same stateMachine state — on every replica.
# FLP (Fischer, Lynch, Paterson 1985):# no deterministic protocol can guarantee BOTH safety AND# liveness in a fully asynchronous network, even with one# crash failure. Below is the shape of WHY.on receive heartbeat from leader:reset election_timeouton election_timeout fires:# The protocol cannot distinguish:# leader is SLOW (timeout was too aggressive — wait)# leader is CRASHED (timeout was correct — elect new)# Any deterministic resolution in finite time can be# made WRONG by an adversarial scheduler.start_election()
Where this sits in Build Raft — consensus you can defend
Scene 01 of 12. Consensus on a replicated log lets N deterministic state machines converge — but FLP forbids any deterministic protocol from being both safe and live in a fully asynchronous network. Raft fixes safety as a theorem, concedes liveness to partial synchrony.
Up next. Now that you know correctness (safety) is the part Raft must guarantee no matter what the network does, the next scene asks: how can the servers even agree on the ORDER of commands when nobody trusts wall-clock time?
All 12 scenes in Build Raft — consensus you can defend · Every curriculum