Implementing Database Replication 00:00:01 The primary goes quiet at position eight A checkout primary disappears while two followers have different log positions. Follow the vote and the membership change. What keeps a returning old primary from accepting another checkout? All three are healthy. Logs: 8, 8 and 7. The primary is unavailable. Writes fail from now on. The heartbeat timeout passes. Both replicas agree: two of three. The old primary is cut off, so that it cannot accept a write if it wakes up. Replica 1 becomes primary in a higher term. Replica 2 follows the new primary and the proxy points to it. Clients reconnect. A timeout starts an investigation or election. Safe promotion also requires the protocol's voting and log rules, and the old owner's writes must be fenced. 00:00:54 A second leader across a broken link The network splits a live primary from its voters. First try immediate promotion, then replay the same failure using the pictured lease protocol and a conservative expiration boundary. The old primary lives on one side, the voters on the other. Replica 1 is promoted at once. Both sides accept writes. Play it again. The old primary cannot renew its lease and steps down by itself. After the lease has certainly run out, replica 1 is promoted. The old node sees term 2, accepts it and becomes a follower. A lease needs explicit bounds on clock drift and validity. Enforce ownership at the write destination so a paused process cannot simply resume with yesterday's authority. 00:01:38 Two confirmations out of three A client records version two. One copy is offline, leaving precisely two confirmations. When the missing copy returns, predict what one read response could hide. Nodes 1 and 2 confirm. Node 3 is down. It still has version 1. The other nodes are fine. One of the two must have seen the write. The newest version wins. With the loose setting a read could use node 3 alone and miss the write. Only one copy is left. No quorum, so writes are refused instead of being half done. In this fixed set, a read of two intersects a completed write of two. Version ordering and the handling of concurrent writes remain part of the protocol. 00:02:22 Rejoin at the last shared record Two logs agree through position eight. Each has a different record at nine, and a client heard that the old record succeeded. Do not casually declare that receipt meaningless. Both logs agree up to 8. Then the old leader has its own 9. A client received confirmation for the divergent record named X. Preserve that record and its receipt for reconciliation. The old node goes back to the point where the histories split. It replays 9 and 10 from the new leader and is a healthy replica again. Preserve the divergent record for reconciliation before following the chosen history. Acknowledgment rules determine whether losing such a confirmed write was an allowed recovery outcome. 00:03:05 The replica is gone but its slot remains A connector disappears while the database continues writing. Its replication slot still asks the primary to retain older log files. Watch free storage become part of the availability budget. The slot keeps the log until the replica has it. That takes a moment. The machine is gone, the slot is not. Log piles up. With a limit the slot is invalidated instead, and the primary lives. The replica must then be rebuilt. Monitor retention and subscriber lag, and define the reseeding path. A retention limit can invalidate an unusable slot, trading consumer recovery work for protection against unbounded log growth.