What is Replication?
Replication, told as a story about keeping the same guest log copied in several warehouses.
A fire in the warehouse, and the whole log is gone.It only lived in one place, so there's nothing to recover.
Keep it in one place, and if that place fails, it's gone.Betting everything on a single spot is risky.
The same log, copied into two or three warehouses.If one burns down, the rest still have it.
The leader handles writes, the rest just copy.It takes a moment to arrive, and if the leader fails, a follower takes over.
While copying, you might get a slightly stale answer.And two warehouses both insisting they're the leader is a real problem.
Replication = keeping the same log copied across several warehouses. The leader handles writes and the rest just copy, so the service survives even if one warehouse fails.
Copying data across multiple servers. There's a leader and followers; synchronous replication updates immediately, asynchronous replication catches up a bit later (consistency). When a follower takes over from a failed leader, that's called failover.
When grown-ups say it
- Replication
- Keeping the same log in several warehouses. The service keeps running even if one warehouse fails.
- Leader/follower
- The warehouse that writes, and the ones that just copy. There's one leader, but there can be many followers.
- Replication lag
- The short time it takes to copy over. During that gap a follower may answer with slightly old data.
- Read replica
- A follower dedicated to reads. It takes read load off the leader.
- Sync / async replication
- Whether copying happens instantly or a bit later. Instant is safer but slower.
- Multi-region
- Putting a follower in a whole different city. It survives even if one whole city has trouble.
- Eventual consistency
- Getting a slightly different answer while copying is still in progress. Given enough time, every copy agrees.
- Failover
- A follower stepping up to be leader when the leader fails. Deciding who becomes the new leader is a vote. → control rooms raising hands to decide