Replication
A gentle introduction to database replication. Single-leader, Multi-leader, and Leaderless configurations explained in simple way.
Hi Friends,
Welcome to the 51st issue of the Polymathic Engineers. This issue is reserved for paid subscribers and will be focused entirely on database replication.
Replicating a database means keeping a copy of the same data in multiple locations that are usually connected by a network. It is a powerful technique that can make your applications faster and more resilient to failures, but it's not as easy as flipping a coin.
There are many options available, and each one has its own tradeoffs. To make the right choice, you need to understand each solution's advantages and guarantees and disadvantages and guarantees that do not provide.
I will give you all the information you need in this article. Here is the outline:
Why replicating a database
Synchronous vs. asynchronous replication
Replication topologies
Single leader replication
Replication Lag
Single leader replication
Failover strategies
Multi Leader replication
Leaderless replication
Why replicating a database
There are three main reasons to replicate a database:
Reduce the latency. Latency is the time that a request is waiting to be handled. Regardless of how fast a database is, read and write operations performance depends on the round trip time between the client that started the request and the server that hosts the database. Replicating helps reduce the latency, keeping the database geographically close to the clients.
Maximize the throughput. At a certain point, a single server can no longer serve all the clients. You can use a more powerful machine and scale vertically or have multiple servers and scale horizontally. In this case, having several databases with the same data helps increase the throughput and serve more clients.
Increase fault tolerance. Saving all the data in a single database server makes the system less resilient to failures. If something bad happens, the clients can't access the data stored on the server anymore. The server may take a while to recover, and the whole system would be unavailable for all that time. So, keeping a copy of the data in other servers allows clients to send their requests anyway, increasing the system's availability.