14. Replication
1
The picture to keep in your head2
14.1 Why keep copies of the same data?3
14.2 How does leader-follower replication work?4
14.3 Should the leader wait for followers before confirming a write?5
14.4 What is replication lag, and why does it happen?6
14.5 How do you stop lag from confusing users?7
14.6 How do you use read replicas in practice?8
14.7 What happens when the leader fails?9
14.8 What is split brain, and how is a leader safely chosen?10
14.9 When would you have more than one leader?11
14.10 How does leaderless replication work, and what are quorums?12
Memory card and where the analogy breaks13
Practice: five levels14
Interview questions15
Solutions16
Sources17
Code lab14. Replication
Sources
3 min read+10 XP
Source notes
- Leader-follower replication, write-ahead log shipping and synchronous standby settings, and
pg_stat_replication: PostgreSQL documentation (high availability, replication). MySQL binary log and semi-synchronous replication: MySQL documentation. - Leaderless replication, quorums (N, W, R), hinted handoff, read repair and Merkle-tree anti-entropy: Giuseppe DeCandia et al., "Dynamo: Amazon's Highly Available Key-value Store", SOSP 2007; Apache Cassandra documentation for consistency levels.
- Raft: Diego Ongaro and John Ousterhout, "In Search of an Understandable Consensus Algorithm", USENIX ATC 2014.
- GitHub split-brain incident: GitHub, "October 21 post-incident analysis" (https://github.blog/news-insights/company-news/oct21-post-incident-analysis/), describing a network partition, Orchestrator promoting primaries in another region, data reconciliation, and the decision to stop cross-region automatic promotion.
- Patroni (PostgreSQL high availability) and Orchestrator (MySQL topology and failover): project documentation.
- All bookstore numbers are illustrative assumptions; arithmetic computed 2026-10-08.
- Level 3 and Level 4 code: tested 2026-10-08 (
code/ch14_replication.py, all checks pass).