Question presented to candidate: "What is database replication and why do we use it? Explain how a leader and its followers stay in sync, the difference between synchronous and asynchronous replication, and what can go wrong for users and for your data when replicas lag or the leader dies."
What a strong answer should cover:
- Replication keeps copies of the same data on several machines for high availability, read scaling and locality โ and is not a backup (it copies mistakes too)
- Single-leader: all writes go to the leader, which streams its change log (the WAL / binlog) to followers; reads may go to followers
- Synchronous vs asynchronous commit: wait for a replica (slower writes, no loss of acknowledged writes if that replica is promoted) vs do not wait (fast, but a failover can lose recent acknowledged writes); quorum and semi-sync in between
- Replication lag anomalies and fixes: read-your-writes (route to leader or track the write position), monotonic reads (stick a user to one replica)
- Failover: detect, promote the most up-to-date follower, redirect clients, fence the old leader to avoid split brain
- Multi-leader and leaderless (quorum) replication, and why they need conflict resolution
Clarifying questions expected:
- Is losing the last second of acknowledged writes acceptable, or must every acknowledged write survive a failover?
- Are users in one region or several, and what read and write volume is expected?
Code / implementation expected: Optional โ a clear explanation with examples; the example simulates a leader and two followers on a fake clock.