What is Replication?

Keeping a copy of the same data on multiple machines. Each node that stores the copy is called Replica.

Advantages of Replication

1. Parallel Processing: Master: Handles all write operations, Slaves: Handles all read operations
2. Reliable(Data is served even DB crashes, or some DB goes down under load): Data will be served from other slave
3. Highly available(Even if some of DBs are down, client will get response): Since some slaves will be up.

Types of Replication

Type Meaning Digram
Master/Slave or

Leader/Follower
Master/Leader: 1 node is designated as master. Client does RW operations with master. Session is stored in master's DB. Then slaves read from it.
Slaves: Read Only. slave database gets copies of the data from the master database. All slaves replicate data from most updated slave via replication log.

Advantage

1. Parallel Processing: Read(Slaves), Write(Master) is supported paralally
2. Reliable: Since multiple copies of data is maintained
3. Highly availabile:

Disadvantage
  a. Logic is required to promote slave to master(when master fails)
  b. If high number of slaves, more write operations can lead to replication lag.
Master Slave DB
Master/Master or
Active/Active or
Leader/Leader
There are 2 or more leader nodes. Client can write to any 1 of leader. Other leaders will act as slave and read all data from present leader.