System Design (Day -5)

Manoj KumarManoj Kumar
3 min read

Data Replication strategies on the server

Data replication involves copying and maintaining the data inside the Database, to ensure that consistent and reliable access to the data they need.

Types of Data replication

Master Slave replication
Master Master replication(Peer to Peer)

Master Slave Replication
1. We have primary database (master) that handles all the write operations, and one or more Secondary database (slaves) that will handle all the read operation.
2. Whenever there is a update in the Master node then the slaves will copy that data and store that in their nodes.
3. if any read operations are happening from the server means that are navigated to the slave nodes to reduce the load on the master server.
4. If Master fails while writing something then that will be a single point of failure, and that data will be lost, then any one of the slaves will become the Master node.

Master Master Replication (Peer to Peer)
1. We’ll have primary and secondary Database these both databases will accept the read and write operation and they are in sync with each other to stay consistent.
2. if any of the one database fails then another will take up the read and write operations alone, there is no single point of failure in this one.
3. But what if the two databases are not failed but only the communication between these two database are failed, then that is the huge problem,
4. Let’s say we have 2 databases which are in the Master - Master replication and 2 servers that are connected to individual databases, the communication between databases fails, that means the data is not in sync with each other, if User 1 is doing some transaction from server 1 and 2, he has a balance of 150Rs in his account first he has taken 100 rs from the server one call, assuming, and again 100Rs from the server 2, wait what He has only 150Rs in his account but how can he takeout the 200 Rs from the database that is call the Split-brain Problem, so that the database 2 don’t know that already 100 Rs is deducted from the account, it assumes the user has 150Rs of balance in his account. and it will transfer that money.
5. For this problem we have a solution, We can add another node to the existing one, that 3 instances will connect as triangle, if one database has lost its connection with another node, then there is 3rd node which will make sure that the three databases are in sync with each other before doing any write operation on to the database.

Why These Replication?
1. It avoids, Single point of failure, with the master slave architecture, single or multiple copy, of the master data.
2. We can scale-out the read operation with the help of slaves, the write operations goes to the Master node, and the read operations goes to the slaves so that, we can read the data more efficiently so that more stress will be applied on the slaves than master.

0
Subscribe to my newsletter

Read articles from Manoj Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Manoj Kumar
Manoj Kumar