Home / Database Types / Article
DATABASELAB TECHNICAL GUIDE

Distributed Consensus Protocols: Raft vs. Multi-Paxos, Leader Election, and Quorum Lease Physics

📜
Distributed Systems Theory & Consensus Mechanics
An authoritative computer science dissertation on Distributed Consensus Protocols. We formulate Leslie Lamport’s Paxos (Single-Decree and Multi-Paxos), dissect Ongaro and Ousterhout’s Raft protocol (Leader Election, Log Replication, Safety Invariants), analyze Leader Leases and Linearizable Read optimizations, evaluate Joint Consensus cluster membership changes, and benchmark CockroachDB, TiKV, and etcd.

In distributed database engineering, reaching agreement among a cluster of independent, unreliable computing nodes over an asynchronous network is the fundamental prerequisite for correctness. Without distributed consensus, building distributed transactions, distributed metadata locks, and linearizable storage engines is mathematically impossible.

For decades, consensus was dominated by Leslie Lamport’s seminal Paxos algorithm. However, due to the extreme conceptual opacity of Paxos, Diego Ongaro and John Ousterhout introduced Raft in 2014—a consensus protocol explicitly designed for understandability, decomposition, and operational safety. Today, the world’s most resilient distributed databases (CockroachDB, TiDB, YugabyteDB) and coordination clusters (etcd, Consul) rely on Raft and Multi-Paxos to deliver mathematically unbreakable fault tolerance.

1. The Classical Paxos Protocol: Single-Decree to Multi-Paxos

Formalized by Turing Award winner Leslie Lamport, Single-Decree Paxos allows a set of nodes to agree on a single arbitrary value despite node crashes and message delays. Paxos decomposes nodes into three roles: Proposers, Acceptors, and Learners.

Single-Decree Paxos operates in two distinct phases:

  • Phase 1a (Prepare): A Proposer selects a unique proposal number n and broadcasts a Prepare(n) message to a majority of Acceptors.
  • Phase 1b (Promise): If n is greater than any proposal number the Acceptor has previously seen, the Acceptor responds with a Promise never to accept proposals numbered less than n, returning the highest-numbered proposal it has already accepted (if any).
  • Phase 2a (Accept Request): Once the Proposer receives promises from a quorum majority of Acceptors, it chooses a value v (the value of the highest proposal returned, or its own value if none were returned) and broadcasts Accept(n, v).
  • Phase 2b (Accepted): If the Acceptor has not promised to ignore proposal n, it accepts the proposal and notifies the Proposer and Learners.

The Evolution to Multi-Paxos:
While Single-Decree Paxos agrees on a single value, databases require agreeing on an infinite sequence of transactions (a distributed log). Running Phase 1 for every single transaction requires two network round trips (2 RTT) per commit. Multi-Paxos optimizes this by electing a stable leader: Phase 1 is executed once during leader election, allowing the stable leader to execute subsequent log entries in a single network round trip (1 RTT) using only Phase 2, matching theoretical network efficiency limits.

2. The Raft Consensus Protocol: Decomposition and Understandability

Unlike Paxos which merges leader election and state agreement, Raft decomposes distributed consensus into three independent, cleanly isolated subproblems: Leader Election, Log Replication, and Safety Invariants.

In a Raft cluster, every node exists in one of three states: Follower, Candidate, or Leader. Time is divided into arbitrary Terms identified by monotonically increasing integer term numbers.

1. Leader Election:
Followers expect continuous periodic heartbeats (AppendEntries RPC) from the Leader. If a follower’s election timer (randomized between 150ms and 300ms) expires without receiving a heartbeat, it increments its term, transitions to Candidate, votes for itself, and broadcasts RequestVote RPC to all cluster peers. If it receives votes from a quorum majority (N/2 + 1), it becomes the authoritative cluster Leader.

2. Log Replication:
Client write requests are submitted exclusively to the Leader. The Leader appends the command to its local log as an uncommitted entry and broadcasts AppendEntries RPC to followers. Once a quorum majority of followers replicate the entry to non-volatile disk, the Leader commits the entry, applies it to its local state machine, and returns success to the client. The Leader notifies followers of the commit in subsequent heartbeats.

3. Raft Safety Invariants: Preventing Divergence and Split Logs

Raft guarantees absolute state machine consistency by enforcing five mathematical invariants:

  • Election Safety: At most one leader can be elected in a given term. (Guaranteed because each node casts at most one vote per term, and winning requires a majority quorum).
  • Leader Append-Only: A leader never overwrites or truncates its own log entries; it only appends new entries.
  • Log Matching Property: If two logs contain an entry with the same index and term, then the logs are identical in all entries up through the given index.
  • Leader Completeness: If a log entry is committed in a given term, that entry will be present in the logs of the leaders for all higher-numbered terms. (Guaranteed by the voting rule: a follower rejects a candidate’s vote request if the candidate’s log is less up-to-date than its own).
  • State Machine Safety: If a server has applied a log entry at a given index to its state machine, no other server will ever apply a different log entry for the same index.

4. Leader Leases and Linearizable Read Optimizations

In standard Raft, answering a read query strictly requires the Leader to execute an AppendEntries heartbeat round with a quorum of followers to verify it has not been deposed by a network partition (preventing stale reads). However, executing network I/O for every read request throttles read throughput.

Modern distributed databases solve this via Leader Leases:

Leader Lease: Followers grant the Leader an exclusive time-bound lease (e.g., 5 seconds) during which they promise never to initiate an election

While the lease is active, the Leader is mathematically guaranteed to remain the sole authoritative leader, allowing it to satisfy read requests entirely from local memory in under 100 microseconds with guaranteed Linearizability!

5. Raft vs. Multi-Paxos Technical Benchmark Matrix

The comparative engineering characteristics of Raft and Multi-Paxos are contrasted below:

Evaluation Metric Raft Consensus Protocol Multi-Paxos Protocol
Algorithmic Complexity Moderate; cleanly decomposed into leader election and log replication Extremely high; complex state transitions and hole-filling logic
Leader Requirement Strict Leader required for all writes and log appends Symmetric protocol; can operate with or without stable leader
Normal Write Commit Latency 1 Network Round Trip (Leader -> Followers -> Leader) 1 Network Round Trip under Multi-Paxos with stable leader
Log Invariants Strict: logs cannot have missing holes; followers must match leader Permissive: logs can accept out-of-order entries with temporary holes
Membership Changes Joint Consensus or Single-Server reconfiguration protocol Alpha-reconfiguration protocol (complex majority intersections)
Prominent Implementations etcd, CockroachDB, TiKV, HashiCorp Consul, Kafka (KRaft) Google Spanner, Apache Cassandra (Lightweight Transactions)

6. Joint Consensus: Non-Disruptive Cluster Membership Changes in Raft

In real-world production operations, servers fail, hardware is upgraded, and cluster capacity must be expanded or shrunk. However, changing cluster membership (e.g., transitioning from a 3-node cluster to a 5-node cluster) poses a catastrophic vulnerability: if different nodes transition to the new configuration at slightly different times, the cluster can elect two independent leaders simultaneously!

To execute zero-downtime membership reconfigurations, Diego Ongaro introduced Joint Consensus:

Joint Consensus Configuration: C_old,new requires agreement from BOTH a majority of C_old AND a majority of C_new

The Two-Phase Reconfiguration Protocol:
First, the Leader logs and commits a transitional joint configuration entry C_old,new. While operating under C_old,new, any leader election or log commitment requires independent majority approvals from both the old server set and the new server set simultaneously. Once C_old,new is committed, the Leader safely issues a second entry establishing the final configuration C_new. This mathematical protocol prevents split majorities with absolute safety.

7. Raft Log Compaction and Snapshotting Physics

In a database operating for years, an append-only consensus log would accumulate petabytes of historical state changes, consuming infinite disk storage and causing newly added nodes to spend weeks replaying logs from the beginning of time. Raft resolves this via Snapshotting:

  • State Machine Checkpointing: Each node periodically writes an immutable snapshot of its current state machine (e.g., a point-in-time key-value database dump) to non-volatile storage.
  • Log Truncation: Once the snapshot is safely persisted on disk, the node discards all log entries prior to the snapshot’s last included index and term, keeping consensus logs compact and RAM usage strictly bounded.
  • InstallSnapshot RPC: If a lagging follower or newly provisioned node falls so far behind that the Leader has already truncated the needed log entries, the Leader bypasses standard log replication and streams its complete disk snapshot directly to the follower via InstallSnapshot RPC.

8. The Flp Impossibility Result and the CAP Theorem in Distributed Consensus

To understand the theoretical boundaries of distributed consensus, computer scientists must study the foundational impossibility results established by distributed systems theory:

1. The FLP Impossibility Theorem (Fischer, Lynch, Paterson – 1985):
In a purely asynchronous distributed network where message delivery can be delayed indefinitely, No deterministic consensus protocol can guarantee both Safety and Liveness in the presence of even a single unannounced fail-stop node crash.

Because Raft and Paxos prioritize absolute Safety (Consistency) above all else—guaranteeing that conflicting transactions can never be committed—they must make pragmatic concessions regarding liveness: they utilize randomized election timers or leader leases to ensure progress in practice, even though an adversarial network could theoretically delay messages forever.

2. The CAP Theorem Alignment:
Under Eric Brewer’s CAP Theorem, distributed consensus engines (Raft, Multi-Paxos) are strictly CP Systems (Consistency and Partition Tolerance). If a network partition splits a 5-node cluster into a majority partition of 3 nodes and a minority partition of 2 nodes:

  • The majority partition continues to accept writes because it commands a quorum (3 > 5/2).
  • The minority partition strictly rejects all writes, choosing to sacrifice availability rather than accept split-brain writes that violate linearizability.

9. Multi-Raft Architecture: Scaling Beyond Single-Raft Bottlenecks

In standard Raft implementations (like etcd), a single global Raft consensus group manages the entire cluster. Every single transaction must be proposed and committed by the identical single leader. In a hyperscale distributed database managing petabytes of data across thousands of machines, a single Raft leader’s CPU and network interface would instantly become overwhelmed.

To achieve horizontal scalability, modern NewSQL databases (CockroachDB, TiKV) pioneer the Multi-Raft Architecture:

Multi-Raft: Instead of one global consensus group, the database is partitioned into thousands of small, independent Raft consensus groups

The Operational Mechanics of Multi-Raft:

  • Range-Level Consensus: Each table range (e.g., a 64MB partition) forms its own isolated Raft group with 3 or 5 replicas distributed across physical servers.
  • Leader Distribution: A physical server can act as the Raft Leader for Range A, a follower for Range B, and a follower for Range C. Because leadership is distributed evenly across hundreds of servers, write ingestion scales linearly with the number of nodes in the cluster!
  • Heartbeat Batching: Running 100,000 independent Raft groups on a single machine would flood the network with millions of individual heartbeat messages per second. Multi-Raft engines solve this by multiplexing and coalescing heartbeats for all ranges sharing the same physical network link into a single batched TCP packet.

10. Summary of Consensus Protocol Selection

When engineering distributed infrastructure, systems architects apply these guidelines:

  • Default to Raft for New Systems: Due to its modular formalization, available production libraries (such as hashicorp/raft and tikv/raft-rs), and clean state machine invariants, Raft is the industry standard for modern distributed state machines.
  • Leverage Multi-Paxos for Specialized Asymmetric Networks: For specialized wide-area network infrastructures requiring flexible leaderless proposals or complex WAN optimizations (such as Google Spanner’s Paxos implementation), Multi-Paxos remains a formidable engine.

11. Formal Verification of Consensus Protocols via TLA+ and Jepsen:
Because distributed concurrency bugs can hide behind rare millisecond network interleavings that never trigger during unit tests, distributed systems engineers verify consensus correctness using TLA+ (Temporal Logic of Actions). Leslie Lamport’s formal specification language models all possible state transitions across nodes and networks, exhaustively testing state space models for invariant violations before a single line of production code is written. Furthermore, production binaries undergo continuous chaos torture testing via Jepsen: injecting split-brain network partitions, paused clock skew, and sudden server kills while validating strict linearizability and serializability against external client read-write logs.

12. Consensus Latency Profiling across Wide Area Networks (WAN)

When consensus clusters span geographically distributed regions across continents (e.g., New York, Frankfurt, and Singapore), network physics dictates operational performance boundaries:

  • Speed-of-Light Latency Floors: Photonic propagation through fiber optics incurs approximately 5 microseconds of latency per kilometer. Transatlantic round-trip network ping between New York and Frankfurt is physically bounded at ~75ms.
  • Quorum Fast Paths: In a 5-node cluster deployed across 3 continents, placing 3 nodes in low-latency geographic proximity (e.g., 2 in US-East, 1 in US-Central, 1 in EU, 1 in AP) allows the cluster leader to achieve majority consensus (3 votes) locally in under 15ms without waiting for responses from high-latency transoceanic nodes!
  • Pipelined Raft Replication: Advanced consensus implementations (like CockroachDB and TiKV) decouple log proposal from consensus acknowledgment, streaming log entries continuously across network sockets via HTTP/2 and gRPC without waiting for round-trip acknowledgments on each individual transaction, maximizing WAN bandwidth saturation.
TC

Taryn Crooks

Senior Databaselab Specialist

Senior Agricultural Researcher & Livestock Husbandry Specialist at Databaselab. Dedicated to advancing sustainable flock management, genetic conservation, and precision ovine nutrition.

Leave a Comment