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