IT PAPER DEEP-READ · PAPER 50

Raft: Consensus Built to Be Understood

Diego Ongaro & John Ousterhout · Stanford · USENIX ATC 2014

中文 →

What did this paper do?

In 2014, two Stanford researchers (Diego Ongaro and John Ousterhout) introduced Raft—a set of rules that lets a group of computers "agree on the same thing, and never take it back." Many of the big systems you use every day (Kubernetes, the database CockroachDB, service registries like etcd / Consul) have a small cluster of machines quietly backing each other up and watching one another, so that "even if a few die, the survivors remember exactly the same record and never disagree." Raft is that agreement rulebook. Its most unusual feature isn't being faster or stronger—it was deliberately designed to be readable and to be implemented correctly.

An analogy first

Picture a team where everyone holds an identical notebook listing, in order, "the operations we've performed." The rule: every notebook must stay line-for-line identical forever; once a line is "locked in," it can never be changed or dropped—not even if someone dozes off or a passed note gets lost. Getting a group of drowsy members over an unreliable channel to keep their notebooks perfectly matched has a proper name: consensus.

The old-world pain

Consensus already had a canonical answer, called Paxos, proposed in 1990 (its author won a Turing Award). The trouble: it's notoriously hard to understand. Textbooks couldn't make it click, engineers couldn't fully grasp it, and anyone building a working system on it had to bolt on their own unproven patches. An algorithm where "one small mistake causes disaster," yet almost nobody truly understands it, is itself a serious hazard. Raft's authors simply made "being understandable" the number-one design goal and let everything else fall in line behind it.

How Raft pulls it off

Three moves, all humble.

First, elect a single captain (leader): at any moment only the captain may write new lines; everyone else just copies the captain's notebook. Information always flows from the captain to the members—unlike the old approach where anyone could propose and things turned to chaos.

Second, elect the captain with random timers: each person holds a little countdown timer set to a random length; if they hear nothing from a captain for a while, whoever's timer rings first stands up and asks "vote me captain?" Because the lengths are random, two people rarely stand at once; if they tie, each re-rolls a new random time and the deadlock quickly breaks.

Third, only a majority counts: after the captain writes a line, it counts as "locked in" only once more than half the team has copied it. The beauty is that any two "more-than-half" groups must overlap, so the next captain is guaranteed to carry every locked-in line—locked-in content can never be lost. One more rule: only someone whose notebook is current enough is eligible to be elected, which slams the door on "a member missing pages becoming captain and leading everyone astray."

What it brought about

Raft turned consensus from black magic only a few experts dared touch into something an ordinary engineer can implement after reading one paper. Countless pieces of infrastructure today—etcd, Consul, TiKV, CockroachDB, Kafka's newer coordination layer—run on Raft or a variant. In a real sense, it made "reliable distributed systems" something anyone can build.

One honest caveat: every write has to pass through the single captain, so the captain is a throughput ceiling; and when the captain drops off, the whole team pauses briefly to elect a new one before continuing. It also guards only against "crashing," not "lying"—it assumes no member is malicious.

Remember this one line

Elect one captain to keep the ledger while everyone copies it, use random timers to pick the captain and "a majority-has-copied-it before it counts" to make locked-in entries un-loseable—Raft rewrote a consensus algorithm no one had understood for thirty years into rules you can actually read and implement correctly, becoming the consistency core of countless modern distributed systems.

Want the role state machine, the replicated-log diagram, and the numbers? → Switch to the deep read