← Back to Articles
Distributed Systems • Consensus Protocols

Distributed Consensus Deep-Dive: Raft, Multi-Paxos & Leaderless Quorum Systems

Distributed Consensus Deep-Dive: Raft, Multi-Paxos & Leaderless Quorum Systems
Raft Consensus Protocol: Replicated State Machine and Quorum Leader Election
Executive Summary & Key Security Takeaways
  • State Machine Replication (SMR): Ensure a distributed cluster of nodes executes the identical sequence of state transitions across network partitions.
  • Raft Consensus: Understand decomposed subproblems: Leader Election (randomized election timeouts), Log Replication, and Safety Invariants.
  • Paxos & Multi-Paxos: Two-phase protocol (Prepare/Promise, Accept/Accepted) driving foundational distributed systems (Google Spanner, Chubby).
  • Leaderless Quorum Systems: Dynamo-style architectures enforcing overlap equations (R + W > N) with Vector Clocks and Read Repair.

1. The Distributed Consensus Problem & Replicated State Machines

In asynchronous distributed systems subject to network delays, packet loss, and machine crashes (Crash Fault Tolerant - CFT model), multiple independent servers must agree on a deterministic sequence of state machine transitions. This paradigm is known as State Machine Replication (SMR).

The FLP Impossibility Theorem proves that no deterministic consensus protocol can guarantee both Safety (never committing conflicting values) and Liveness (eventually reaching agreement) in an asynchronous network with even a single unannounced failure. Consensus algorithms like Raft and Paxos prioritize absolute Safety, sacrificing temporary Liveness during network partitions until quorums are re-established.

// Mathematical Quorum Intersection Principle
// In a cluster of N nodes, any quorum Q1 and Q2 must intersect by at least one node:
// |Q1| + |Q2| > N
// For Majority Quorums: Q = floor(N / 2) + 1
// Tolerated Node Failures: F = floor((N - 1) / 2)
// N = 3 nodes -> Quorum = 2 -> Tolerates F = 1 failure
// N = 5 nodes -> Quorum = 3 -> Tolerates F = 2 failures

2. Raft Protocol: Randomized Timeouts & Log Matching Property

Designed by Ongaro and Ousterhout for understandability, Raft structures consensus around a Strong Leader. Nodes exist in one of three states: Follower, Candidate, or Leader. If a follower misses leader heartbeat pulses within a randomized election timeout (150ms-300ms), it increments its Term counter and broadcasts RequestVote RPCs.

Once elected, the Leader accepts client commands, appends entries to its local log, and broadcasts AppendEntries RPCs. An entry is committed once replicated across a strict majority quorum ($> N/2$). The Raft Log Matching Property guarantees that if two logs contain an entry with the same index and term, they are identical up to that index.

// Go: Raft AppendEntries RPC Request and Handler
type AppendEntriesArgs struct {
    Term         uint64
    LeaderId     int
    PrevLogIndex uint64
    PrevLogTerm  uint64
    Entries      []LogEntry
    LeaderCommit uint64
}

func (rf *RaftNode) AppendEntries(args *AppendEntriesArgs, reply *AppendEntriesReply) {
    rf.mu.Lock()
    defer rf.mu.Unlock()
    
    // Reject outdated term leaders
    if args.Term < rf.currentTerm {
        reply.Success = false
        reply.Term = rf.currentTerm
        return
    }
    // Reset heartbeat timer
    rf.lastHeartbeat = time.Now()
    reply.Success = true
}

3. Classic Paxos vs Multi-Paxos Pipeline Optimization

Leslie Lamport Classic Paxos achieves consensus on a single value through two phases: Phase 1 (Prepare / Promise) where proposers acquire proposal number rights, and Phase 2 (Accept / Accepted) where acceptors commit the highest-numbered value.

Because running Phase 1 for every individual log entry incurs prohibitive 2-round-trip network latency, production systems implement Multi-Paxos: running Phase 1 once to elect a stable leader, then executing stream-lined Phase 2 Accept rounds directly for subsequent transactions.

// Multi-Paxos Protocol Flow Summary
// Phase 1 (Once during leader startup):
//   Leader -> Prepare(N) -> Acceptors
//   Acceptors -> Promise(N, max_accepted_val) -> Leader
//
// Phase 2 (Per transaction stream):
//   Leader -> Accept(N, slot_index, value) -> Acceptors
//   Acceptors -> Accepted(N, slot_index) -> Leader
//   Leader -> CommitNotification(slot_index) -> Client & Acceptors

4. Leaderless Systems (Dynamo): Quorum Equations & Vector Clocks

In contrast to leader-based protocols, Leaderless distributed databases (such as Amazon DynamoDB, Apache Cassandra, and ScyllaDB) allow clients to write directly to any arbitrary replica node.

Tunable consistency is achieved via the Quorum Equation: + W > N$, where $ is the replication factor, $ is the write acknowledgment threshold, and $ is the read replica query count. Concurrent write conflicts across disconnected network partitions are resolved using Vector Clocks or Last-Write-Wins (LWW) timestamps.

// Python: Validating Dynamo Quorum Consistency Guarantees
def is_strong_consistency(replication_factor, read_quorum, write_quorum):
    N = replication_factor
    R = read_quorum
    W = write_quorum
    # Strict quorum overlap guarantees that read set always contains newest write
    return (R + W) > N

Frequently Asked Questions (FAQ)

How does Raft prevent split-brain during network partitions?

Raft requires a strict majority quorum (> N/2) to elect a leader and commit log entries. In a network partition, the minority side cannot form a quorum and cannot commit writes, while the majority side continues processing transactions safely.

What is the practical difference between Raft and Paxos?

Both offer identical formal safety and fault tolerance. Raft is explicitly decomposed into independent, understandable subproblems (leader election, log replication, safety invariants), whereas Multi-Paxos is an optimized pipeline of classic two-phase consensus.

What is Byzantine Fault Tolerance (BFT) compared to Crash Fault Tolerance (CFT)?

CFT protocols (Raft, Paxos) assume nodes are honest and only fail by stopping. BFT protocols (PBFT, Tendermint, HotStuff) tolerate malicious nodes that actively lie, forge messages, or collude, requiring 3F + 1 total nodes to tolerate F Byzantine failures.

Zyekh Abdul Qadir Jailani

Written by Zyekh Abdul Qadir Jailani

Digital Forensics & Incident Response (DFIR) Specialist & Security Researcher specializing in Linux kernel hardening, threat hunting, and system security research.

Utility Security Tools Related to this Article:

Gunakan Subnet Calculator dan Diff Checker untuk membantu alur kerja konfigurasi keamanan Anda secara privasi di browser.