Distributed Systems
Passive Replication
Primary Server
Server Replacement
Network Architecture

Passive Replication in Distributed Systems - Replacing the Primary Server

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

In the realm of distributed systems, passive replication stands out as a fault-tolerance technique that involves having a primary server handle all client requests while other backup servers, or replicas, remain idle until they are needed. This replication strategy is particularly relevant when considering the scenarios in which the primary server needs replacement, either due to failures or routine maintenance.

Passive versus Active Replication

First, it's essential to distinguish between passive and active replication:

  • Passive Replication: Also known as primary-backup replication, this involves a single primary server processing and responding to all requests. State updates are sent to passive replicas, which do not handle client requests until the primary fails.
  • Active Replication: Here, all replicas simultaneously process each request. This can lead to higher resource use but provides immediate failover capabilities without service interruption.

Scenario: Replacing the Primary Server

Consider a scenario in which the primary server develops a fault and needs replacement. The steps typically involved in passive replication to replace a primary server can be outlined as follows:

  1. Detection of Failure: The failure of the primary server is detected by heartbeat mechanisms or through a watchdog system.
  2. Selection of New Primary: One of the passive replicas is selected to become the new primary server. This selection can be based on several factors, such as synchronization status, hardware capabilities, or simply a predefined priority order.
  3. State Synchronization: If the new primary server's state is not fully synchronized with the old primary at the time of failure, it must first update its state. This is typically done by applying any missed updates from a synchronization log or a state transfer from other replicas.
  4. Role Transition: Once synchronized, the new primary takes over the role, adjusting its operation mode from passive to active, and begins to service client requests.
  5. Notification of Clients: Clients are informed about the change in the primary server, often through a service discovery mechanism that directs them to the new primary.

Technical Considerations

State Transfer Mechanism

The effectiveness of passive replication significantly depends on the mechanism used for state transfer between the primary and backup servers. State transfer can be done in two ways:

  • State Transfer at Checkpoints: Periodically, the primary server sends a snapshot of its entire state to the backups.
  • Log Shipping: Every state-changing operation is recorded in a log file, which is shipped to the backup servers, allowing them to replay these operations to maintain an up-to-date state.

Examples

Example 1: Database Servers In a distributed database, passive replication might involve a master database receiving all write operations, while multiple slave databases receive logs of these operations to replay. If the master fails, one of the slaves is promoted to be the new master, involves updating its log to the latest before taking over.

Example 2: File Servers Consider file servers where the primary server handles all write requests to files, periodically sending snapshots of these files to backup servers. Upon primary failure, the most synchronized file server is promoted to handle requests, minimally impacting system availability.

Challenges

Synchronization Delay: The time required for replicas to synchronize can lead to periods where no adequate backup is available, posing a risk. Resource Underutilization: Passive replicas do not actively serve requests, which can lead to resource underutilization, affecting the cost-efficiency of the system.

Summary Table

FeaturePassive ReplicationActive Replication
Resource UtilizationLow (backup servers mostly idle)High (all servers active)
Implementation ComplexityModerateHigh
Failover TimeHigher (due to promotion and possibly state sync)Lower (all servers are always in sync)
ConsistencyStrong (single source of updates)Requires careful handling to avoid divergence

Conclusion

Passive replication, in the context of replacing the primary server in a distributed system, offers a methodical and efficient way to handle server failures with minimal disruption. While it may not be as resource-efficient as active replication, its relative simplicity and strong consistency model make it suitable for many critical applications requiring high availability.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.