Relationship between primary-backup and state machine replication
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
The concepts of primary-backup and state machine replication are central to designing robust distributed systems. Both strategies provide mechanisms to ensure system availability and consistency in the face of failures, but they approach the problem differently, often complementing each other.
State Machine Replication (SMR)
State Machine Replication is a method used to ensure that a set of computers (nodes) in a distributed system agrees on a sequence of operations to perform, maintaining consistency across disparate systems. The core idea is to model the service as a deterministic state machine. Determinism ensures that all nodes that start in the same state and apply the same sequence of commands will end in the same state.
A typical SMR setup involves:
- Leader Election: Electing a leader node to coordinate the order of messages.
- Log Replication: The leader replicates its command log across all follower nodes.
- State Machine Execution: Each node executes commands from the replicated log on its local state machine.
A classic example of SMR is the Raft consensus algorithm, which is famously deployed as a part of distributed datastores like etcd used in Kubernetes.
Primary-backup Replication
The primary-backup replication technique, also known as master-slave replication, involves designating one node as the primary (or master) and other nodes as backups or slaves. Here, the primary node handles all client requests and also updates the backups:
- Write Responsibilities and Data Flow: All client operations are sent to the primary server. The primary then processes these operations and forwards update information to the backup servers.
- Failure Handling: In case the primary fails, one of the backup servers is promoted to be the new primary, ensuring service continuity.
This approach is simpler than SMR in cases where there is a clear distinction between read-heavy and write-heavy loads since it allows reading from any node, but synchronizes writes through the primary.
Intersection of State Machine and Primary-backup Replication
The intersection of these two methodologies is particularly interesting in systems where both robust fault tolerance and efficient data replication are required:
- Using SMR for Consensus and Coordination: Using SMR, systems can achieve consensus about which node is the primary and how backups are synchronized, improving the overall fault tolerance of primary-backup systems. For example, a system might use Raft to agree upon which node is the primary, ensuring that this decision is made robustly.
- Hybrid Systems for Reconfiguration: In dynamic environments, systems might leverage SMR for managing reconfiguration (e.g., changing which nodes are part of the system) and use primary-backup for regular operation, optimizing performance and fault tolerance.
Here is a simple table to summarize the differences and synergies between State Machine and Primary-backup Replication:
| Feature | State Machine Replication | Primary-backup Replication |
| Model Type | Theoretical/Abstract | Practical/Operational |
| Node Roles | Homogeneous | Heterogeneous |
| Operational Complexity | High | Moderate |
| Use of Consensus | Integral | Optional |
| Fault Tolerance | Very high | High (depends on implementation) |
| Data Synchronization | Across all nodes | From primary to backups |
| Typical Use Cases | Distributed databases, Systems requiring strong consistency | Web application databases, Systems where quick reads are crucial |
Conclusion
In conclusion, while state machine replication offers a robust framework for achieving consensus and maintaining strong consistency across distributed systems, primary-backup replication provides a simpler, more direct approach to data redundancy and system reliability. In many modern distributed systems, leveraging the strengths of both strategies provides a comprehensive solution that maximizes availability, reliability, and consistency.
Related reading
- Reliable fire-n-forget Kafka producer implementation strategy
- Reliably running hundreds of scheduled functions every minute
- replicas in replication
- replicate a row tensor using tf.tile?
- Reliability of atomic counters in DynamoDB
- Reload django object from database
- replicate data from a realtime table to another table in SQL Server 2008R2?
- Replicate Dynamic loaded groovy classes in cluster nodes

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.