🔄Key Takeaways
- 1Single-leader (primary-replica) is the most common pattern — one writer, many readers
- 2Multi-leader enables writes at multiple locations but creates conflict resolution complexity
- 3Leaderless (Dynamo-style) uses quorum reads/writes for tunable consistency
- 4Sync replication = strong consistency but slower; Async = fast but risk of data loss on failover
Why Replicate?
Replication copies data across multiple nodes for three reasons: (1) High availability — if one node dies, others serve traffic, (2) Performance — read replicas handle read-heavy workloads, (3) Durability — data survives hardware failures.
The fundamental challenge: how do you keep multiple copies of data in sync, especially when the network is unreliable?
Replication Topologies
One primary (leader) accepts all writes. Changes are replicated to follower replicas. Reads go to any replica.
Most common pattern. Used by PostgreSQL, MySQL, MongoDB (default), Redis.
Async replication: primary doesn't wait for replicas to confirm → fast writes but followers may lag (replication lag = stale reads).
Sync replication: primary waits for at least one replica to confirm → slower writes but guarantees at least two copies.
Quorum condition: W + R > N
Example configurations (N=3):
W=2, R=2 → Consistent reads (overlap = 1 node)
W=3, R=1 → Fast reads, slower writes
W=1, R=3 → Fast writes, slower reads
W=1, R=1 → Fastest but NO consistency guarantee
For strong consistency: W + R > N
For high write availability: W = 1 (any single node can accept writes)
For high read availability: R = 1
Trade-off: lower W or R = higher availability/speed but weaker consistencyAdvantages
- •High availability through redundancy
- •Read scalability via replicas
- •Durability — data survives node failures
Disadvantages
- •Replication lag causes stale reads
- •Conflict resolution in multi-leader is complex
- •Sync replication reduces write throughput
🧪 Test Your Understanding
In a quorum system with N=5, W=3, R=3, is consistency guaranteed?