System Design Notes
Don’t forget to get your copy of Designing Data Intensive Applications the single most important book to read for system design interview prep!

Asynchronous vs Synchronous Replication

There are broadly two strategies that can be adopted for replicating changes from the leader to its followers. These are:

  • Asynchronous Replication
  • Synchronous Replication

The two can be combined to form a hybrid strategy, sometimes called semi-synchronous replication.

Asynchronous Replication

In the leader-based replication model, there is a spectrum that defines how replication from the leader to the followers takes place. On one end of the spectrum is the asynchronous replication, which involves the leader registering a change locally and then immediately returning a success message in response to a client’s write request. The leader doesn’t wait for the change to propagate to its followers before informing the client that the client’s write request has been successfully processed. The hope is that the leader will be able to transmit the change to its followers without crashing or some other issue such as a network partition occurring.

1. Writes are accepted at the leader only.

2. Leader acknowledges the write request to the client without waiting for the request contents to be replicated to the followers.

3. Followers receive the updates from the leader after the client is already sent a success acknowledgement.

The pro of this approach is that the number of write requests that can be processed by such a system is very high since the leader doesn’t wait for the change to be replicated to its followers. Failure of one or more followers doesn’t hinder the leader and write requests can continue to be processed.

However, the con of this approach is that in case the leader fails before the latest changes can be propagated to the followers, the changes are lost forever. The writes aren’t guaranteed to be durable even when the client has been notified of a successful write as the leader can fail without getting a chance to replicate the write to its followers

Synchronous Replication

At the other end of the spectrum lies synchronous replication, which entails that a change is propagated and registered by all the followers before the leader can return a success message to a client in response to a write request.

1. Client sends a request to the leader.

1. Client sends a request to the leader.

2. Leader replicates the write request to all the followers.

3. Client is sent an acknowledgement only after all the replicas record the change.

3. Client is sent an acknowledgement only after all the replicas record the change.