Module 19 / Algorithms behind big systems

Module 19 · lesson 21 of 22 · Read 10 min

Paxos

The original consensus algorithm, and how it relates to Raft.

Earlier in this module you saw Raft elect a leader and replicate a log. Raft was published in 2014 with one explicit goal: to be easier to understand than Paxos. Paxos is older (Leslie Lamport described it in the late 1980s), it is famous for being confusing, and it still runs inside some of the most important systems on the planet.

The good news is that the core of Paxos, the part that gets a group of machines to agree on one value, fits on an index card. In this lesson we'll trace it by hand, see where it gets stuck, and then see how it grows into something that looks a lot like Raft.

The problem: agree on one value

Tiffin runs a nightly payout job that pays restaurants. It must run on exactly one machine. Three scheduler nodes start up at midnight, and each would happily volunteer. They need to agree on one answer to "who runs payouts tonight?" even though:

  • messages can be lost, delayed or arrive out of order,
  • any node can crash and restart,
  • there is no trusted clock and no referee.

This is the consensus problem. A correct answer must be safe: once a value is chosen, it stays chosen, and nobody ever learns a different one. We would also like it to be live: eventually something gets chosen. Paxos guarantees safety always, and liveness only when things are calm enough. That split is the most important idea in this lesson.