Yashotantra Academy logo

2 · Distributed Core & Consensus

3. Distributed Consensus: Raft & Paxos

Leader election, replicated state machines, log replication, and split-brain resolution.

11 min read · 3 MCQs

Replicated State Machine Model

A group of distributed nodes acts as a fault-tolerant single state machine by ensuring all nodes execute the exact same sequence of log entries in the same deterministic order. If majority nodes agree on the log, consensus is established.

Raft Core Phases

Raft decomposes consensus into three distinct sub-problems: Leader Election (nodes use randomized election timers to nominate leaders via majority votes), Log Replication (the leader accepts client commands, appends them to its log, and forces follower logs to match), and Safety (only nodes with complete committed logs can be elected leader).

Quorum Math & Split-Brain Prevention

To survive $F$ node failures, a cluster requires $2F + 1$ total nodes. An odd number of nodes (3, 5, or 7) ensures that any two quorums must share at least one overlapping node, mathematically preventing two independent leaders from forming across a network split (split-brain).

// Quorum calculation
const totalNodes = 5;
const majorityQuorum = Math.floor(totalNodes / 2) + 1; // 3 nodes
const faultTolerance = Math.floor((totalNodes - 1) / 2); // Can tolerate 2 failed nodes

Chapter quiz

3 questions · pass mark 75%
  1. 1. How many nodes are needed in a Raft consensus cluster to safely survive 2 simultaneous node failures?

  2. 2. What prevents 'split-brain' in a partitioned consensus cluster?

  3. 3. What role do randomized election timers play in Raft?