The Replicated State Machine Model
What you'll learn: How Raft and other consensus algorithms use replicated state machines to keep multiple servers in sync by applying the same commands in the same order.
Core Idea
A replicated state machine is a design pattern where multiple servers maintain identical copies of state by executing the same sequence of deterministic commands in the same order. Think of it like multiple calculators all receiving the same button presses in the same sequence—they'll all display the same result.
The key insight: if you start with identical initial states and apply identical operations in identical order, you end up with identical final states (assuming deterministic execution).
How It Works in Raft
Raft implements this model through replicated logs:
- Client commands arrive at the leader
- Leader appends the command to its log
- Leader replicates the log entry to followers
- Once a majority confirms, the entry is considered "committed"
- Each server applies committed entries to its state machine in log order
The log acts as the synchronization mechanism. Every server processes log[0], then log[1], then log[2], and so on. Even if servers crash and restart, they catch up by replaying the log from where they left off.
Why Determinism Matters
Commands must be deterministic—no reading the current time, no random numbers, no depending on external state. Given the same input, they must produce the same output every time. This ensures all replicas stay identical.
If you need non-deterministic values (timestamps, UUIDs), the leader decides them and includes them in the log entry, so all followers use the same value.
Key Takeaway: The replicated state machine model achieves fault-tolerant consensus by having all servers maintain identical logs and execute the same deterministic commands in the same order, ensuring all replicas converge to identical states.