State machine replication explained in plain terms is one of the most elegant ideas in distributed systems. The central question is how several servers can act as one reliable machine when any of them might crash, and the answer is to make them all run the same program, feed them the same commands in the same order, and let determinism do the rest.
If every server starts from the same state and applies the same sequence of commands, each one reaches the same state, produces the same outputs, and any of them can answer for the group. The hard part is agreeing on the sequence of commands, and that is where consensus protocols come in.
This article explains how state machine replication works, the rules that keep replicas in step, and where the approach breaks down.
Key takeaways
- State machine replication runs the same deterministic program on several servers.
- Every replica applies the same commands in the same order.
- Agreement on the command order comes from a consensus protocol.
- Any replica can answer for the group, because all hold the same state.
- The program must be deterministic; randomness and clocks break replication.
What state machine replication is
A state machine is a program with a state and a set of commands that change it. A key-value store is a state machine: its state is the set of keys and values, and its commands are put and delete. A bank account is a state machine too, with deposit and withdraw as commands.
State machine replication, often shortened to SMR, runs that program on several machines at once. Clients send commands to the group, the group agrees on an order for them, and each replica applies them in that order. Because the program is deterministic, the same commands in the same order always produce the same state, so the replicas stay identical.
The idea was set out by Leslie Lamport in the late 1970s, and it underpins much of modern infrastructure. When you write to a distributed database or a configuration store, there is a good chance that state machine replication is what makes the write durable and consistent.
How replicas stay in step
The process has three parts. First, a client sends a command to the group, usually to the current leader. Second, the group runs a consensus protocol to agree on where the command goes in the shared log, which is simply the ordered list of all commands so far. Third, each replica applies the commands from the log in order, updating its local copy of the state.
The log is the heart of the design. It is the single source of truth about what happened and in what order, and a replica that falls behind can catch up simply by replaying the log entries it missed. A new replica can join by copying the log and replaying it from the start, which is how the group grows.
Outputs are produced as a side effect of applying commands. When a replica applies a read command, it returns the result from its local state, and because all replicas hold the same state, any of them can answer. When a replica applies a write, it updates its state and sends no output, or sends an acknowledgement, and again the result is the same on every replica.
The determinism rule
Determinism is the one rule that cannot be bent. The program must produce the same result every time it runs the same commands in the same order, with no dependence on anything outside the log. That means no reading the local clock, no random numbers, and no looking at the local disk for values that differ between machines.
In practice, anything non-deterministic must be turned into a command. If the program needs the current time, the leader reads the time once and puts it in the command, so every replica uses the same value. If it needs a random number, the leader generates it once and includes it in the command. The trick is to move the non-determinism out of the replicas and into the agreed log.
Violating the rule is a quiet disaster. Two replicas that take different branches on a clock reading will hold different states, and from that moment the group disagrees about everything, with no easy way to find the point where they diverged. Testing for determinism, and keeping it, is one of the most important disciplines in building a replicated system.
Where consensus fits in
State machine replication does not solve the ordering problem itself; it delegates it to a consensus protocol. Paxos and Raft are the two classic choices, and both do the same job: they let a group of machines agree on the next entry in the log, even when some machines crash or messages are lost.
The leader plays a central role in most designs. Clients send commands to the leader, the leader proposes them to the group, and once a majority has accepted a proposal, the command is committed and every replica applies it. If the leader crashes, the group elects a new one, which picks up where the old one left off, because the committed log entries survive the election.
The combination is powerful because each half does what it is good at. Consensus handles agreement on order, and the state machine handles the meaning of the commands, so the two can be developed and tested separately. Our guide to Raft explains the consensus protocol most teams choose today, and our guide to Paxos explains the original that Raft simplified.

State machine replication compared with other designs
Replication can be done in several ways, and state machine replication is the strictest. Primary-backup replication sends commands to one server and copies the results to the others, which is simpler but leaves a window where the backup lags. Quorum replication, by contrast, writes to a subset and reads from a subset, which is cheaper but gives weaker guarantees.
The table below sets out the main contrasts.
| Aspect | State machine replication | Primary-backup | Quorum replication |
|---|---|---|---|
| Consistency | Strong, all replicas identical | Strong, after backup catches up | Tunable, depends on R and W |
| Survives leader crash | Yes, new leader elected | Yes, backup promoted | Yes, if a quorum survives |
| Read latency | Low, any replica answers | Low, primary answers | Moderate, asks several replicas |
| Write cost | High, consensus per command | Low, one primary writes | Moderate, waits for W replies |
| Best for | Configuration, coordination | Simple databases | Large clusters, flexible needs |
The practical result is that state machine replication suits small, critical datasets where correctness matters more than speed, while larger or more flexible workloads use the cheaper designs.
Where state machine replication is used
Configuration stores are the classic case. etcd, which holds the configuration of every Kubernetes cluster, is a replicated state machine built on Raft, and every change to a cluster passes through its log. ZooKeeper, the older coordination service, works the same way, with a log of commands applied in order by every server.
Distributed databases use it for their metadata, even when their main data takes a different path. A database may shard its rows across hundreds of machines, but the map of which machine holds which shard is kept in a small replicated state machine, because losing that map would lose everything.
Blockchain systems are state machines too, in a more public form. Each block is a batch of commands, the chain is the log, and every node applies the same commands in the same order to reach the same ledger state, which is state machine replication with a different consensus protocol underneath.
It is also used in fault-tolerant control systems, where a physical process must keep running through computer failures. Three computers run the same control program, vote on the outputs, and a faulty one is outvoted by the other two, which is the same idea applied to hardware rather than data. Our guide to the write-ahead log explains the durable record that lets a replica rebuild its state after a crash.
Strengths and limits
The greatest strength of state machine replication is its simplicity of reasoning. Once the log is agreed, every replica is the same, every read can be served locally, and the whole system behaves like a single reliable machine, which makes it far easier to reason about than most distributed designs.
It is also a strength that the approach composes well. The same pattern works for a three-node configuration store and for a global ledger, because the log abstracts away the details of what the commands mean, and the consensus protocol abstracts away the details of how agreement is reached.
The limits are real, though. Every command goes through consensus, which caps throughput and adds latency, and every replica holds the full state, which caps the size of the dataset. A replicated state machine cannot hold a terabyte of data on every node, so large systems use it for metadata and shard the bulk data elsewhere.
State machine replication checklist
- Make the state machine deterministic; no clocks or random numbers inside.
- Put every non-deterministic value into the command itself.
- Agree on command order with a proven consensus protocol.
- Keep a durable log so replicas can catch up and rejoin.
- Snapshot the state regularly so a new replica need not replay everything.
- Elect a new leader quickly when the old one fails.
- Use it for small critical datasets, not for bulk data.
- Test what happens when a replica applies a command twice.
- Monitor log growth; an unbounded log eventually runs out of disk.
Frequently asked questions
What is state machine replication in simple terms?
It is running the same deterministic program on several servers, feeding them the same commands in the same order, so they all stay in the same state.
What is the role of the log?
The log is the ordered list of all commands. Replicas apply it in order, catch up by replaying entries they missed, and new replicas join by copying it.
Why must the state machine be deterministic?
Because any difference in how replicas execute the same command would leave them in different states, breaking the whole guarantee of the design.
How is state machine replication different from primary-backup?
In primary-backup one server executes and copies results, while in state machine replication every server executes the same commands, so any replica can take over instantly.
What consensus protocols are used with it?
Paxos and Raft are the standard choices; both agree on the next log entry even when some machines crash or messages are lost.
Can state machine replication handle large datasets?
Not directly, because every replica holds the full state. Large systems use it for metadata and shard the bulk data by another method.
The bottom line
State machine replication explained in one line is this: same program, same commands, same order, same state, on every machine.
It is the idea that turns a group of unreliable servers into one reliable machine, and it sits underneath more of modern infrastructure than most people realise.
This article is general information about how state machine replication works, not advice about building a replicated system.







