What is replication lag, and why does a follower fall behind the leader?
Sketch your own answer first, then compare it with the one below.
A strong answer
Replication lag is the gap between a write being committed on the leader and the same write being visible on a follower. It can be measured in time or as a number of log entries the follower has not applied yet.
Followers fall behind because the log has to travel over a network that takes time and takes a different time on each trip, because a busy follower applies entries slower than they arrive, and because entries are applied in order, so one delayed message holds up everything behind it.
Lag matters because a read from a follower can return data older than a write the client was told succeeded. Lag is a window, not a loss: the follower catches up once the burst passes. It grows with the write rate, with network delay, and with a follower busy on other work.
Sources
- Martin Kleppmann (2017). Designing Data-Intensive Applications.
- Douglas Terry, Alan Demers, Karin Petersen, Mike Spreitzer, Marvin Theimer, Brent Welch (1994). Session Guarantees for Weakly Consistent Replicated Data.