Database Replication
Keeping copies of your database for availability and read scaling.
1The Backup Band Analogy
Database replication copies data from one database (primary/leader) to others (replicas/followers) for redundancy and read scaling.
2Replication Types
Synchronous
Primary waits for replica to confirm write. Strong consistency but higher latency.
Asynchronous
Primary writes immediately, replica catches up later. Risk of data loss on failure.
Semi-synchronous
Wait for at least one replica. Balance of safety and speed.
3Architectures
Single-Leader
One primary handles writes, replicas handle reads. Most common.
Multi-Leader
Multiple primaries accept writes. Complex conflict resolution.
Leaderless
Any node accepts writes. Quorum-based reads/writes (Dynamo-style).
Chain Replication
Writes go through chain of nodes. Strong consistency.
4Replication Lag
Replication lag is the delay between a write on primary and its appearance on replicas. Can cause stale reads.
Read-Your-Writes
User writes, then reads from replica that hasn't caught up. Solution: route user's reads to primary.
Monotonic Reads
User sees new data, then old data on different replica. Solution: sticky sessions to same replica.
5Key Takeaways
?Quiz
1. Synchronous replication trades what for data safety?
2. User writes a comment, refreshes, doesn't see it. Cause?