Replication: copies, lag, and the read you cannot trust
The replica is not a backup, and the seconds it lags are where stale data bites.
What you will be able to do
- Compare leader-follower, multi-leader, and leaderless replication
- Diagnose stale reads caused by replication lag
- Design a read-your-own-writes guarantee
- Explain failover, promotion, and split brain
Three topologies
| Topology | How writes flow | Failure behaviour |
|---|---|---|
| Leader-follower | All writes to one leader, replicated to followers | Leader dies: promote a follower. Followers die: reads come from the rest |
| Multi-leader | Several leaders accept writes, replicate to each other | Leads to write conflicts that must be resolved |
| Leaderless (quorum) | Client writes to several replicas, reads from several | No promotion needed; consistency set by R + W > N |
Leader-follower is the default for application databases because it keeps writes simple. Multi-leader exists when regions must accept writes while a cross-region link is unreliable — and it forces you to answer: which write wins when two users edit the same record at once?
Lag is a product decision
Replication is asynchronous by default. If the leader commits and fails before shipping the change, the follower never sees it — the write is lost. Synchronous replication closes that gap but makes writes wait for a remote round trip.
"Read from replicas" sounds free and is not. The user posts a comment, the redirect goes to a page served by a lagging replica, and their comment is missing. That is the classic read-your-own-writes bug, and it is a design bug, not a caching quirk.
Failover and the split-brain problem
How to say it out loud
"Primary takes writes; three replicas serve reads in the same region. Posts are read-your-own-writes, so the writer is pinned to the primary for two seconds after publishing. Timelines tolerate roughly one second of staleness. Failover promotes a replica through the orchestrator and repoints the service; the old primary rejoins as a replica." That paragraph answers availability, consistency, and failure in one breath.
Worth remembering
- Replication buys read scale and availability, and pays with lag and failover complexity.
- A replica can be behind by milliseconds or minutes; the design must state what staleness is acceptable.
- Read-your-own-writes is usually solved by pinning the user to the leader briefly or tracking a version.
- Split brain happens when two nodes both believe they are leader; fencing tokens and quorum promotion prevent it.