advanced
Replication
Copy data for read scale and availability while managing lag, failover, consistency, and conflict behavior.
Replication copies data to multiple nodes for read scaling and failover. Leader-follower (primary-replica) is common: writes go to the leader, reads may hit replicas with replication lag. Multi-leader and leaderless models trade write availability for conflict resolution complexity.
Measure replication lag — stale reads break invariants for balances and permissions. Automate failover with consensus (Raft, Paxos) or orchestrated promotion with fencing to avoid split-brain writes.
On interviews: diagram primary-replica read path, state lag tolerance for your use case, and failover steps.
Common pitfalls: reading from replica immediately after write; no fencing during failover; treating replicas as backup without restore drills.
The trade-off is flexibility versus complexity—know when the simpler path is enough.
Checklist:
- Choose replication topology for consistency needs.
- Monitor and alert on replication lag.
- Define read routing rules per query type.
- Test failover and split-brain prevention.