Replication, Consistency and Transactions
Know exactly what each replication scheme and isolation level promises, which anomalies it still allows, and what the stronger guarantee costs in latency and availability.
Key points
- 1
Asynchronous followers lag. Session guarantees (read-your-writes, monotonic reads, consistent prefix) patch the common anomalies cheaply, for example by pinning a user's reads to one replica.
- 2
Leaderless quorums overlap when R + W > N, but sloppy quorums, concurrent writes and last-write-wins clocks all break the 'always fresh' intuition.
- 3
Snapshot isolation prevents dirty reads, non-repeatable reads and lost updates, but allows write skew. Fix write skew with SERIALIZABLE (SSI), FOR UPDATE locks on the premise rows, or a constraint.
- 4
Serializability is about transactions matching some serial order; linearizability is about recency in real time. Strict serializability is both.
- 5
2PC blocks: a participant that voted YES can neither commit nor abort until it learns the decision, so make the coordinator's log highly available.
- 6
PACELC: even without a partition, strong consistency costs latency. A cross-region majority write costs at least one round trip to the nearest follower.
Common traps
A YES vote in 2PC is not a commit; other participants may have voted NO.
READ COMMITTED doesn't fix write skew; it allows even more anomalies than snapshot isolation.
Raft and Paxos commit on a majority, not on every replica, so one failed replica out of three doesn't stop writes.
Read the source
Further reading
Suggest a resource- Strong consistency models(opens in a new tab)Kyle Kingsbury's explanation of linearizability, serializability and the weaker models between them.Articleaphyr.comEditor’s pick
- Please stop calling databases CP or AP(opens in a new tab)Martin Kleppmann on why the CAP labels mislead and what to reason about instead.Articlemartin.kleppmann.comEditor’s pick
- Eventually Consistent - Revisited(opens in a new tab)Werner Vogels on client-side consistency guarantees such as read-your-writes and the N, R, W quorum trade-off.Articleallthingsdistributed.comEditor’s pick
Test yourself on Replication, Consistency and Transactions
Ten questions, with the answer and explanation after each one.