Three topologies
| Topology | Writes go to | Pros | Cons | Used by |
|---|---|---|---|---|
| Single-leader | One leader | Simple, no write conflicts | Leader is a write bottleneck; failover needed | PostgreSQL, MySQL, MongoDB |
| Multi-leader | Several leaders (e.g. one per region) | Local writes in every region | Write conflicts must be resolved | Multi-region setups, collaborative apps |
| Leaderless | Any replica (quorums) | No failover, high availability | Weaker consistency, read repair needed | Cassandra, DynamoDB-style stores |
Synchronous or asynchronous?
- Synchronous: the leader waits for a follower to confirm before acknowledging the client. No data loss if the leader dies, but slower writes, and a slow follower stalls everything.
- Asynchronous: acknowledge immediately, replicate in the background. Fast, but the last few writes can be lost on failover.
- Semi-synchronous (common in practice): wait for one follower synchronously, the rest async.
Tip
In interviews, link this to RPO: "For orders we need RPO ≈ 0, so I'll use semi-synchronous replication to a standby in another availability zone. Read replicas can be async."
Living with replica lag
Async followers trail the leader by milliseconds, or by seconds under load. This creates three classic anomalies:
- Read-your-writes: you update your profile, refresh, and see the old version (the read went to a lagging replica). Fix: read your own data from the leader for a short window after writing, or pass the write's log position and read from a replica that has caught up.
- Monotonic reads: you see a comment, refresh, and it disappears (second read hit a more-lagged replica). Fix: pin each user to one replica (hash user ID).
- Consistent prefix: you see an answer before its question. Fix: keep causally related writes in the same partition, or track causality.