4 · Databases: choosing & replicating · Replication

Replication

AppwritesreadsPrimaryasyncReplica 1Replica 2
Leader–follower
One primary takes writes; replicas copy its log and serve reads. Scales reads, not writes.
Replication lag
Async replicas are behind by ms–seconds. A user may not see their own write → read-your-writes from primary for that user.
Sync vs async
Sync: no data loss on failover but slower writes. Async: fast, but recent writes can be lost.
Failover
Promote a replica when the primary dies. Risk: split brain (two primaries) — needs fencing/consensus.
Multi-leader / leaderless
Writes in several places (multi-region, Dynamo-style). Must resolve conflicts.