Explained step by step
Replicating means sharing data among several copies of the database so they all stay the same. It makes the system more reliable, fault tolerant and able to serve more reads. It's like having the same address book on your phone, computer and tablet: if you lose one, the others remain. With 1 main database and 2 copies, if 1 server breaks, the data is still in 2 places.
Replication has costs too: it adds hardware and complexity. If the master goes down, there can be time without writes and even data loss: what the master wrote but hadn't copied to the slaves yet is lost. Also, every write goes through the master, which can become a bottleneck. It's like a dictation: if the teacher leaves before you copy the last sentence, nobody has that sentence.
In master-slave replication, the master serves reads and writes, and copies each write to 1 or more slaves, which only serve reads. Slaves can also copy to other slaves, like a tree. It's like a teacher writing on the board while students copy: only the teacher writes, but everyone can read. With 1 master and 3 slaves, writes go to 1 server and reads are spread over 4.
If the master goes down in master-slave, the system can keep going in read-only mode: slaves keep answering, but nobody can write. That lasts until a slave is promoted to master or a new master is set up. It's like the teacher being absent: students can read what's on the board, but nobody adds anything until the substitute arrives. Promoting a slave can take from seconds to minutes.
Master-slave is very useful when there are more reads than writes. Apps read from slaves without loading the master, and backups can be taken from a slave without affecting it. A slave can also be taken offline and synced back with no visible outage. It's like a library with 1 original and 10 photocopies for reading: the original doesn't wear out. If there are 100 reads per write, adding slaves is the natural way to grow.
In master-master there are 2 masters that read, write and coordinate with each other. If one goes down, the other keeps reading and writing, and fail-over is simple and fast. In exchange, it's harder to set up, and either data is loosely consistent or writes take longer because of syncing. With more masters, conflicts appear: 2 people change the same data at once on 2 servers. It's like 2 secretaries with the same calendar: if both book a slot at 10, someone must decide which one counts.
Replication lag is the delay between the master writing data and the slaves receiving it. While it lasts, a slave can return old data. The more slaves, the more copies to make and the more the lag can grow. It's like a rumor: the first person knows instantly, but the tenth hears minutes later. If you change your name and read from a slave with 2 seconds of lag, you see the old name.
The difference between synchronous and asynchronous replication is when data reaches the copy. In synchronous, it's written to the primary and the copy at the same time: they're always equal, but each write waits for both. In asynchronous, it's written to the primary first and copied later, sometimes on a schedule: cheaper and faster, but the copy can lag behind. It's like sending a message and waiting for 'read' (synchronous) or sending it and moving on (asynchronous).