Consensus Algorithms: Raft & Paxos
Master distributed consensus — how nodes agree in the face of failures, leader election, log replication with Raft, quorum-based decisions, split brain prevention, and how etcd, ZooKeeper, and CockroachDB use consensus in production.
Master distributed consensus — how nodes agree in the face of failures, leader election, log replication with Raft, quorum-based decisions, split brain prevention, and how etcd, ZooKeeper, and CockroachDB use consensus in production. This hands-on tutorial focuses on practical implementation of consensus algorithms: raft & paxos concepts.
Consensus Algorithms: Raft & Paxos
How do multiple servers agree on a single value when any of them might crash or lose network connectivity at any moment? This is the distributed consensus problem, and it's the foundation of every reliable distributed system — from Kubernetes (etcd) to CockroachDB to Apache ZooKeeper.
[!IMPORTANT] The FLP Impossibility theorem (1985) proves that no deterministic consensus algorithm can guarantee progress in an asynchronous system with even one faulty process. Real systems work around this by using timeouts (not truly asynchronous) and randomized leader election to break symmetry.
What Is Consensus?
Consensus requires three properties:
- Agreement: All non-faulty nodes decide on the same value
- Validity: The decided value was proposed by some node
- Termination: All non-faulty nodes eventually decide
Raft Algorithm
Raft was designed to be more understandable than Paxos while providing the same guarantees. It decomposes consensus into three sub-problems: leader election, log replication, and safety.
Quorum — The Core of Consensus
The key insight of all consensus algorithms: require a majority (quorum) for any decision. This ensures that any two majorities overlap in at least one node — guaranteeing no split decisions:
Quiz
Quiz
Question 1 of 2You have a 5-node etcd cluster. 2 nodes simultaneously fail. Can the cluster still serve writes?
Official Resources
- Raft — Understandable Consensus (Original Paper)
- Raft Visualization — Thesecretlivesofdata.com
- Paxos Made Simple — Leslie Lamport
- etcd — Production Raft Implementation
Key Takeaways
✅ Consensus = multiple nodes agreeing on a single value despite failures.
✅ Raft simplifies Paxos: leader election, log replication, safety — three separate sub-problems.
✅ Quorum (majority) is the key to preventing split-brain — only one side of a partition can have majority.
✅ 5-node cluster tolerates 2 simultaneous failures while remaining available.
✅ etcd (Raft), ZooKeeper (ZAB), CockroachDB (Raft) all use consensus in production.
What's Next?
Consensus enables agreement. Now explore the most advanced scaling techniques.
Next: Designing for Global Scale — Multi-region active-active, geo-routing, data sovereignty, and global load balancing.