Why Consensus Is Needed
anywhere "exactly one" must be trueConsensus is getting a set of machines to agree on a single value even when some of them fail. You need it wherever exactly one of something must be true across the cluster: one leader (Replication), one holder of a distributed lock (Concurrency Control), one authoritative cluster membership list (Discovery), one agreed config value. Get disagreement here and you get split brain, double execution, corruption.
Why It's Hard
you can't tell slow from deadOn an asynchronous network, a silent node is indistinguishable from a slow one â no reply could mean crashed, or just lagging. FLP (the Fischer-Lynch-Paterson result) makes it formal: in a fully asynchronous network where even one node can fail, no algorithm can guarantee consensus in bounded time. You can't have perfect agreement, guaranteed termination, and fault tolerance all at once.
Quorums
majority overlap is the whole trickThe core mechanism is a majority. Require more than half the nodes to agree on anything, and a beautiful property falls out: any two majorities must share at least one node. That shared node can't vote for two conflicting decisions, so two leaders can never both win, two conflicting values can never both commit.
5 nodes. A majority is 3.
any set of 3 ââ
any other 3 ââ MUST overlap in âĨ1 node (3+3 > 5)
that node refuses to back both â no split decision
This is why clusters are ODD: 3, 5, 7.
3 nodes tolerate 1 failure (majority of 3 = 2)
5 nodes tolerate 2 failures (majority of 5 = 3)
an even count adds a node without adding fault tolerance (4 also tolerates 1)
Odd sizes are the norm because they maximize fault tolerance per node: 5 nodes survive 2 failures, and a 6th node doesn't buy a third. The cluster keeps working as long as a majority is alive; lose the majority and it stops accepting writes rather than risk a split decision â the CP choice (CAP).
Raft: The One to Know
designed to be teachableRaft splits consensus into two understandable pieces: elect a leader, then replicate a log through it. Time is divided into terms, each with at most one leader.
LEADER ELECTION
followers wait for the leader's heartbeat.
heartbeat missing past a RANDOM timeout ââļ become candidate,
bump term, request votes from all
get a majority ââļ become leader, start heartbeating
random timeouts make simultaneous candidates (split votes) rare;
a split vote just retries next term
LOG REPLICATION
client write ââļ leader appends to its log ââļ sends to followers
followers ack ââļ once a MAJORITY has it, leader COMMITS
ââļ applies to state machine, tells followers to commit, replies to client
An entry is committed only once a majority has stored it, so a committed write survives any minority failure. On a leader crash, a follower times out and starts an election. On a partition, only the side with a majority can elect a leader and make progress â the minority side stalls, which is what prevents split brain. On a split vote, nobody gets a majority and the randomized timeouts resolve it next term.
Paxos
older, equivalent, notoriously hardPaxos came first and solves the same problem with the same power, but it's famously hard to understand and to implement correctly â Raft was explicitly designed as a teachable replacement. In practice you'll see Multi-Paxos (Paxos optimized for a stream of decisions) inside older systems. Name it, note that Raft superseded it for most new designs, and move on.
Consensus in the Wild
small cluster, big fleetYou rarely implement consensus â you use a system that already did. ZooKeeper, etcd, and Consul are consensus-as-a-service: hand them your leader election, locks, and config, and they run Raft (or Zab) underneath. Many databases embed it directly â CockroachDB, etcd, and Kafka's KRaft mode use Raft internally for their own coordination.
THE PATTERN: keep the consensus cluster SMALL, the data fleet BIG ââââââââââââââââââââââââââââ âââââââââââââââââââââââââââââââââââ â consensus cluster (3â5) â ââââ â large stateless / data fleet â â etcd / ZooKeeper â reads â hundreds of nodes â â leader, locks, config, â coord â serve the actual traffic â â membership â â no consensus on the hot path â ââââââââââââââââââââââââââââ âââââââââââââââââââââââââââââââââââ
What Consensus Costs
never on the hot pathEvery consensus decision needs a round trip to a majority and a durable write on each â so throughput is low and latency includes that quorum wait. That's fine for the handful of coordination decisions a system makes; it's fatal for high-volume data.
Quick Reference
coordination need â tool| Coordination need | Reach for |
|---|---|
| Leader election | etcd / ZooKeeper / Consul (Raft) |
| Distributed lock | Same, with lease + fencing token |
| Cluster membership | Consensus store |
| Config that must be consistent | etcd / Consul KV |
| High-volume data | NOT consensus â replication + sharding |
| Raft state | Meaning |
|---|---|
| Follower | Default; applies the leader's log, resets election timer on heartbeat |
| Candidate | Timed out; requesting votes for a new term |
| Leader | Won a majority; handles writes and heartbeats |
| Term | Logical clock; each has â¤1 leader, bumped on every election |
| Commit | Entry stored on a majority â now durable and applied |