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!

Single Leader Replication

This form of replication is also known as the active/passive or master-slave replication. Consider a group of nodes that host a replica of a database. Out of all the nodes, one of the nodes acts as the leader of the group and the rest are designated as the followers.

  • The leader accepts all the writes from the other participants/clients in the system and writes the change to its local storage. The change is then propagated to the followers. The changes made at the leader must be sent in the same order to the followers. These changes sent from the leader to its followers is also known as the *change stream* or *replication log*.
  • Clients in the system can make a read request either to the leader or any one of the followers. In an ideal situation, all the follower nodes will have caught up to the leader and present the same snapshot of data to the clients as that exists on the leader.

1. Client initiates a write request with the leader

2. Leader propogates the write to other replicas in the system.

3. Leader propogates the write to other replicas in the system.

The astute reader will immediately realize that the above scheme is exposed to a number of issues that can arise when followers try to replicate the changes occurring on the leader node. For instance, what if a follower falls behind the leader by a few minutes and receives a read request from a client that asks for data that is present on the leader but not yet on the follower? There are several intricacies and nuances that go with the subject of data replication and we’ll discuss them next.