How a group of machines agrees on one value, even when some of them fail.
Consensus means getting several machines to agree on one value, even when some machines crash and messages get lost or delayed.
One machine can decide alone. But one machine is a single point of failure. So we use a group, and the group must act like one reliable machine. That needs every healthy node to end up with the same answer, and that answer must have been proposed by someone, not invented.
A consensus algorithm promises three things:
The hard part is that the network is unreliable and nobody can tell a slow node from a dead one. A famous result, the FLP impossibility, says no algorithm can guarantee all three in a fully asynchronous network if even one node may crash. Real protocols therefore always protect safety (never agree on two things) and give up liveness for a while when the network is bad. They use timeouts to make progress most of the time.
| Algorithm | Idea | Used by |
|---|---|---|
| Paxos | Proposers ask acceptors in two phases. A majority accepts. | Google Chubby and Spanner, many internal systems |
| Multi-Paxos | Pick a stable leader, and skip the first phase for later values. | Most production Paxos systems |
| Raft | A clear leader, a replicated log and simple rules. Made to be easy to understand. | etcd, Consul, CockroachDB, TiKV |
| ZAB | A leader orders updates and broadcasts them. Similar to Raft. | Apache ZooKeeper |
| PBFT / Tendermint | Three message rounds that tolerate lying nodes. | Permissioned blockchains |
| Proof of work / stake | Open competition or stake decides who adds the next block. | Public blockchains |
| Cluster size | Majority | Crashes survived |
|---|---|---|
| 3 | 2 | 1 |
| 4 | 3 | 1 (no better than 3) |
| 5 | 3 | 2 |
| 7 | 4 | 3 |
A simplified picture: a majority is more than half of ALL nodes (not just the ones alive), so two sides of a network cut can never both have one. That is why consensus clusters use an odd size: 3 survive 1 crash, 5 survive 2, 7 survive 3. A real protocol (Paxos, Raft) adds the message rounds that are skipped here.
| Term | Meaning in easy words |
|---|---|
| Consensus | Getting several nodes to agree on one value despite failures |
| Quorum | The number of nodes that must agree, usually more than half |
| Safety | Nothing bad happens: nodes never decide different values |
| Liveness | Something good eventually happens: the group does decide |
| Proposer | A node that suggests a value |
| Acceptor | A node that votes on proposals |
| Learner | A node that is told the final decision |
| Leader | The node that drives decisions for a term, so rounds are fast |
| Term / epoch / ballot | A number that grows with each new leader election or attempt |
| FLP impossibility | A proof that perfect consensus is impossible in a fully asynchronous system with one crash |
| Byzantine fault | A node that behaves in a wrong or lying way, not just crashing |
| Choice | We gain | We lose |
|---|---|---|
| Bigger cluster | Survives more crashes | More messages and slower writes |
| Smaller cluster (3) | Cheap and fast | Only one crash tolerated |
| Spread across regions | Survives a region loss | Every write pays cross-region delay |
| Leader-based (Raft) | Simple and fast in the common case | A leader failure causes a short pause for election |
| Leaderless / eventual consistency | Always available, low latency | Concurrent writes and conflicts to resolve |
| BFT instead of CFT | Tolerates lying nodes | More nodes, more messages, more complexity |