The full picture
🎬 Raft: leader election and log replication
1 / 5Term 4: N1 is leader. It sends AppendEntries heartbeats to N2 and N3 to keep them followers — a follower that keeps hearing from a leader never starts an election.
| Mechanism | What it prevents |
|---|---|
| One vote per node per term | two leaders in the same term (split-brain) |
| Randomized election timeouts | endless split votes — someone times out first |
| Majority for both vote and commit | any two quorums overlap, so history can't fork |
| Election restriction (log must be up to date) | a stale node becoming leader and erasing committed entries |
| Commit only entries from the current term | the subtle 'committed then overwritten' bug in naive designs |
- The majority-overlap argument is the heart of it — say it explicitly: any two majorities of the same cluster share at least one node, and that node's vote or log entry is what stitches history together across terms. Every quorum system rests on this one set-theory fact.
- Why odd cluster sizes: 3 nodes tolerate 1 failure, 4 nodes also tolerate only 1 (majority of 4 is 3) — the fourth node adds cost and latency with zero fault tolerance. 5 tolerates 2. This is the single most practical thing to know about running etcd/ZooKeeper.
- Committed ≠ applied ≠ visible: an entry is committed once a majority has it durably; the leader then applies it and answers the client. A follower may apply later, which is exactly why a read from a follower can be stale unless you do a ReadIndex or lease-based read.
- Raft vs the reality of throughput: every write costs one disk fsync on a majority plus a round-trip — consensus clusters are for metadata (leader identity, configuration, locks, small state), not for your main data path. Putting a high-volume workload in ZooKeeper is a classic architecture smell.
- Where you already use it: etcd (so: all of Kubernetes' state), Consul, CockroachDB per-range, TiKV, Kafka's KRaft controller, MongoDB's replica-set elections (Raft-like). Naming two of these grounds the answer immediately.