2 · SQL & databases

4. Transactions, Consistency and Distribution

ACID, isolation levels, MVCC, replication and the CAP trade-off.

10 min read · 3 MCQs

ACID and isolation

Atomicity, consistency, isolation and durability define a transaction. Isolation levels trade correctness for concurrency: read committed (default in many engines) permits non-repeatable reads; repeatable read prevents them; serializable prevents write skew but can abort transactions that must be retried.

MVCC

Multi-version concurrency control keeps multiple row versions so readers never block writers. The cost is version bloat, which vacuum or compaction must reclaim — a common source of mysterious slowdowns in write-heavy Postgres deployments.

Distribution

Replication gives read scaling and failover, but asynchronous replicas lag, so a read-after-write on a replica can return stale data. Sharding partitions data by key for write scaling and makes cross-shard joins and transactions expensive. Under a network partition, CAP forces a choice between consistency and availability.

Chapter quiz

3 questions · pass mark 75%
  1. 1. MVCC's main benefit is…

  2. 2. Serializable isolation may require the application to…

  3. 3. Reading from an async replica risks…

Answer every question to submit. Progress for da-04 is saved in this browser.