TechCoder.io / System Design

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.

By TechCoder TeamLast updated: 2026-10-17
In a Nutshell

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.

PYTHON PLAYGROUND
⏳ Loading editor…

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:

PYTHON PLAYGROUND
⏳ Loading editor…

Quiz

Quiz

Question 1 of 2

You have a 5-node etcd cluster. 2 nodes simultaneously fail. Can the cluster still serve writes?

No — any failure in a distributed system stops all writes
Yes — quorum is 3 (majority of 5); with 2 failures, 3 nodes remain and can form quorum
Yes — the leader handles writes alone regardless of how many nodes fail

Official Resources

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.