DISTRIBUTED DATABASE REPLICATION

Single Master Replication

Understanding Single Master Replication in Distributed Database Systems.

Sriram R
3 min readMar 6, 2023

This replication method designates one of the nodes as the Leader, while the other nodes are designated as Followers. The Leader node is the only node that receives new updates on data, and is responsible for propagating those updates to its followers. This is also known as primary-backup replication.

The followers are usually called Read Replicas, since they cannot receive updates and are used only for Read requests.

Replication Techniques

There are two ways in which the leader can propagate updates to its followers:

  • Synchronous Replication
  • Asynchronous Replication

Synchronous Replication

In synchronous replication, the leader responds to the client only after receiving acknowledgement from all replicas that they have also performed the updates. Essentially, if any replica is unable to commit data, all replicas, including the leader, will not commit the data.

This guarantees that the client is able to read from any node after a successful write, and ensures that data is not lost even if the leader goes down, as we saw in the previous article on replication.

Synchronous Replication Flow

Problems with Synchronous Replication

While synchronous replication can improve data consistency, it also has some drawbacks. Specifically, it can lead to significant write latency because the leader must wait for all replicas to commit the data before responding to the client. Additionally, it is not suitable for write-heavy workloads because all writes are sent to a single leader, rather than being distributed across the system.

Another issue with synchronous replication is that if the leader dies, the system will not be able to process any more reads. To address this, one of the replicas can be chosen as the new leader, but this process is not always straightforward. Leader election algorithms are among the most complex algorithms, and will be covered in an upcoming series.

Asynchronous Replication

Asynchronous replication involves a node responding to a client as soon as it processes a request and propagating updates to its replicas in the background. This approach doesn’t wait for the replicas to process the request before responding to the client. As a result, write requests benefit from significantly improved performance compared to synchronous replication.

Asynchronous Replication Flow

Problems with Asynchronous Replication

Although asynchronous replication can improve write performance, it has its drawbacks. This technique sacrifices read-after-write consistency because there may be a delay between when data is written to the leader and when it is written to the replicas. Replication is done in the background, so a read request can be sent to a replica before the leader has propagated changes, resulting in the read replica responding with stale data.

What happens if a leader dies? In synchronous replication, you can replace the leader with a replica since they are in sync. However, in asynchronous replication, the replicas may not have all the data due to network delays, and there is a possibility of the leader crashing before replicating the latest changes. This can result in data loss, and for your clients, it may appear as if data has vanished. This can be disastrous for certain systems.

Conclusion

Both Synchronous and Asynchronous Single Master Replication have their own strengths and weaknesses. Therefore, it is crucial to understand both and choose the approach that best suits your system.

--

--

Sriram R

A software engineer on the way to a jack-of-all-trades.