Keep copies of your data on several machines for safety and read speed.
Replication means keeping copies of the same data on several machines. If one machine dies, another still has the data. And many machines can answer reads at the same time.
One database on one machine is a risk. The disk can fail. The machine can crash. And one machine can only answer so many reads per second. So we run several copies of the database. Each copy is called a replica. Every write must reach every replica, and that copying work is what we call replication.
The leader writes each change to a log (a list of changes in order). Followers read that log and apply the same changes in the same order. This is why they end up equal.
| Model | Who takes writes? | Good and bad |
|---|---|---|
| Single leader (leader-follower) | Only one leader. Followers are read-only. | Simple. No write conflicts. The leader is one write bottleneck, and failover needs care. |
| Multi-leader | Several leaders, often one per region. They copy each other. | Fast local writes in each region. Two leaders can change the same row, so you need conflict resolution. |
| Leaderless | Any node can take a write. The client writes to several nodes and reads from several. | No single point of failure. You tune quorums (W + R > N) and accept fuzzy consistency (Dynamo, Cassandra style). |
| Mode | Leader waits for | Speed | Safety |
|---|---|---|---|
| Asynchronous | Nothing. It confirms at once. | Fastest | A leader crash can lose the newest confirmed writes. |
| Semi-synchronous | One follower. | Medium | A second copy of every confirmed write exists. |
| Synchronous | All followers. | Slowest | Strongest. But one slow or dead follower stalls all writes. |
NOW(), RAND()) giving a different answer on each copy.The leader says 'done' at once and copies in the background. Fast writes, but a crash can lose the newest ones.
A simplified model with a simulated clock (no random numbers). Failover promotes the follower that is furthest ahead. Real databases add leader election, fencing and catching the old leader up when it returns.
| Term | Meaning in easy words |
|---|---|
| Replica | One copy of the data on one machine |
| Leader / primary / master | The node that accepts writes |
| Follower / secondary / standby | A node that copies the leader |
| Replication log (WAL) | The ordered list of changes that followers apply |
| Synchronous | The leader waits for the copy before confirming |
| Asynchronous | The leader confirms first and copies later |
| Replication lag | How far a follower is behind the leader |
| Failover | Promoting a follower to leader when the leader fails |
| Split brain | Two nodes both think they are the leader |
| Quorum | The minimum number of nodes that must agree (W + R > N) |
| Read-your-writes | You always see your own recent changes |
| Choice | We gain | We lose |
|---|---|---|
| Async replication | Fast writes, tolerant of slow followers | Possible data loss on a crash, stale reads |
| Sync replication | No loss of confirmed writes | Slower writes, lower availability |
| More followers | More read capacity, more safety | More copying work for the leader, more cost |
| Read from followers | Offloads the leader | Stale reads |
| Multi-region replicas | Local reads, disaster recovery | Larger lag, harder conflicts |
| Multi-leader | Fast writes everywhere | Conflict resolution complexity |
DELETE is copied to all followers in milliseconds. You still need point-in-time backups.