Skip to content

Lesson 9 of 9 · 27m

Consensus Basics: Raft, Quorums, and Leaderless Systems

Consensus lets a cluster agree on one ordered history despite failures. Raft is the mental model most engineers should learn first, with quorums as the underlying arithmetic.

Replication copies data. Consensus decides which copy of history is authoritative when nodes crash, restart, or stop hearing each other. It exists because 'the primary' is not a fact of nature; it is a belief that must be coordinated across machines.

The problem: agree on one log

Most consensus systems reduce the hard problem to agreeing on an ordered replicated log. If every correct node applies the same operations in the same order, their state machines converge.

client write -> leader appends log entry 42
             -> replicated to followers
             -> majority acknowledges
             -> entry committed
             -> applied to state machine

That majority is the key. Three nodes need 2 acknowledgements; five need 3. Any two majorities overlap in at least one node, so conflicting committed decisions cannot both win.

Raft in operational terms

Raft has a small set of moving parts:

Nodes are followers, candidates, or leaders. Leaders send heartbeats and replicate entries. If heartbeats stop, followers start an election, candidates request votes for a term, and a candidate with majority becomes leader. Entries committed by a majority cannot be forgotten by later leaders.

This is why etcd, Consul, and many control planes use Raft-like protocols. They do not make failures impossible; they make behavior under failure explainable.

Availability and latency are coupled to quorum

A three-node Raft cluster can lose one node and keep writing. Lose two and it cannot commit. Spreading nodes across availability zones improves fault tolerance but raises latency because every write now waits for cross-zone acknowledgement.

3 nodes in one rack: fast, vulnerable
3 nodes across 3 AZs: slower, much safer
5 nodes across regions: safer still, even slower

Consensus is not a replication accelerator. It is a consistency mechanism, and consistency costs round trips.

Leaderless quorum systems make different trade-offs

Dynamo-style systems often avoid a single leader and use read/write quorums:

N = replicas storing the key
W = replicas that must acknowledge a write
R = replicas that must answer a read

If W + R > N, reads are likely to intersect recent writes, but conflict resolution, hinted handoff, sloppy quorum, and read repair enter your life. 'Eventual consistency' is not a consistency level; it is a warning label unless the reconciliation semantics are explicit.

Split brain is prevented by losing availability

When a network partition happens, the minority side must refuse writes. That is the CAP trade in real operational form: under partition, choose consistency or availability for writes. Correct systems often choose correctness and become unavailable on the minority side. Systems that keep accepting writes everywhere are choosing divergence, whether or not the marketing page says so.

Field notes

  • Prefer odd cluster sizes: 3 or 5 nodes, not 4 or 6, because extra even nodes add latency without improving tolerated failures as much as people expect.
  • Consensus protects metadata and control planes exceptionally well; using it for every high-throughput data write is expensive.
  • A leader is a performance feature as much as a correctness one: it orders work and reduces conflicts, but can become a bottleneck.
  • Read the failure semantics before adopting a system. 'Strong consistency' means different things in vendor documentation and in formal operation.

Was this lesson helpful?

Sign in to rate