Distributed Consensus: Paxos & Raft
Before this, it helps to know: CAP & Consistency in Plain Words.
Read a little, play a little. No scary maths, and no rush.
Scope: this is an overview, not a deep dive. It gives you the intuition a system-design interview tests: why a majority is enough and what a leader actually does. The full protocol is longer than this chapter. If you want the real thing, read Raft's paper and its interactive visualization, which is the best single explanation available, or Jepsen's consistency notes for what the guarantees look like when machines misbehave.
The problem: who's right when nodes disagree?
Run a database on one machine and there's only ever one answer to "what's the current value?" Run it on five machines for durability, and a network hiccup can leave two machines thinking different things are true. Consensus is the protocol that lets a majority of nodes agree on one value — one leader, one committed log entry, one source of truth — even when some nodes are slow, crashed, or temporarily unreachable.
Why "majority," not "everyone"
Requiring all N nodes to agree means one dead machine halts the entire system — the opposite of the fault tolerance you built the cluster for. Requiring a quorum (a majority, e.g. 3 of 5) means the system keeps working as long as a majority is healthy, and — critically — any two quorums overlap by at least one node, which is what prevents two different values from both getting "accepted" during a split.
Paxos vs Raft, in one line each
Paxos proves consensus is possible and is famously hard to implement correctly from the paper alone — it's the theoretical foundation, not usually what you'd hand-roll. Raft was designed explicitly to be understandable: it elects a single leader (via randomized timeouts, so two nodes rarely race for it), the leader sequences all writes into a replicated log, and followers replay that log in order. Most consensus you'll touch in practice (etcd, Consul, CockroachDB's internals) is Raft or a close variant, specifically because it's easier to reason about and debug.
Where you actually meet this
You rarely implement consensus yourself — you depend on something that already has (etcd for Kubernetes' cluster state, ZooKeeper for older Kafka coordination, Raft inside CockroachDB or TiKV). What you need as an engineer is the mental model: a leader election happening somewhere means a brief window with no leader, writes during that window either queue or fail, and that's an availability/consistency tradeoff, not a bug.
A worked example: losing the leader
A five-node Raft cluster is running when the leader's machine dies.
- The followers stop receiving the leader's regular heartbeat. Each waits a slightly different, random amount of time.
- The first to time out becomes a candidate and asks the others for votes. Three votes, including its own, make a majority, so it becomes the new leader.
- For that short gap, often well under a second, writes cannot be committed. Clients retry, and then carry on.
Now suppose instead the network splits the cluster into a group of three and a group of two. The three can still form a majority and keep working. The two cannot, so they refuse writes rather than accept conflicting ones. That refusal is exactly what prevents split-brain.
Why clusters use odd numbers
A cluster of 3 survives 1 failure; a cluster of 4 also survives only 1, because a majority of 4 is 3. The fourth node adds cost without adding fault tolerance, which is why consensus clusters are almost always 3 or 5 nodes.
Remember this
- Consensus = majority agreement on one value, surviving node failures and delays.
- Quorums overlap by design — that overlap is what prevents split-brain disagreement.
- Raft won on understandability: single leader, replicated log, deliberately simple to reason about.
Check your understanding
5 questions · first-try answers earn the most XP
My notes
Saved in this browser. Highlight a line above and save it, or write it in your own words.
Nothing saved yet. Your highlights will live here.
References
Finished reading?
Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.
Practice this in an incident
Try a design drill
End of Distributed Systems
Take the section checkpoint
A short mixed quiz on all 2 chapters, to check you are ready to move on.
Related chapters
Spotted a mistake or want a topic covered? Report an issue