Unit 7 of 14 · about 4 hours · explain
ACID boundaries, dirty and nonrepeatable reads, lost updates and write skew
Isolation levels are names for which anomalies they admit. Without the anomaly shapes the names are marketing; with them each level is a testable claim. The Systems unit on transactions and isolation anomalies built the doctor write-skew history under PostgreSQL. Here the new work is Berenson's phenomenon names and what Maelstrom's weak-model checkers can and cannot detect.
You'll be able to
- Draw the ACID boundary and say which letter each failure threatens.
- Construct dirty-write, lost-update, read-skew and write-skew histories.
- Classify anomalies with the Berenson P0 to P4, A5A and A5B names and say which ones snapshot isolation still admits.
Covers
Read
In this order, only the parts listed
0 of 4 done
- What a transaction promisesDDIA 2e - Chapters 7 and 8 Sharding and Transactions
Chapter 8, What Exactly Is a Transaction (pp. 278-288): The Meaning of ACID, Single-Object and Multi-Object Operations, Figure 8-1 and the retry caveats just before Weak Isolation Levels
- Weak isolation and the doctor on-call skewDDIA 2e - Chapters 7 and 8 Sharding and Transactions
Chapter 8, Weak Isolation Levels (pp. 288-307): Read Committed with dirty reads and writes, Snapshot Isolation with read skew in Figure 8-6, Preventing Lost Updates, and Write Skew and Phantoms with the on-call example in Figure 8-8
- Phenomena P0 to P3 with snapshot anomaliesA Critique of ANSI SQL Isolation Levels (Berenson et al., 1995)
Sections 2 and 3 with Tables 1 to 3 for P0 to P3; Section 4.1 for P4 lost update; Section 4.2 for snapshot isolation, A5A read skew and A5B write skew; Table 4 for which levels admit each
Cite these definitions, not the SQL-92 prose they correct.
- The transfer that must not half-happenAlgoMaster System Design - Selected Sharding and Transaction Problems
The bank-transfer motivation and the ACID definitions: atomicity, consistency, isolation, durability
Focus on
- ACID consistency means your invariants hold; it says nothing about replicas or timing. Isolation is the concurrency half, atomicity plus durability the failure half.
- Dirty reads see uncommitted data, nonrepeatable reads see committed change between two reads, lost updates merge two writes into one, write skew merges two reads into a broken invariant.
- Write skew generalizes lost update: different transactions updating different objects after reading the same set.
- Retry the whole transaction after a definite abort; a rolled-back transaction left nothing to duplicate. A commit whose acknowledgement timed out has an unknown outcome: check its status or retry with a stable ID and atomic deduplication.
Common mistakes · 3
- Calling snapshot isolation serializable. Oracle sells a level named serializable that is snapshot isolation; it admits write skew.
- Blaming the database for a retry double-apply. A commit that timed out before its ack reruns unless the application dedups.
- Treating phantoms as exotic. Any check-then-insert over usernames or bookings is a phantom risk under snapshot isolation.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.One transaction writes x = 3 without committing and another reads x. Which anomaly, and which level admits it?Answer
Dirty read (P1). Only read-uncommitted admits it; PostgreSQL has no such mode and behaves as read-committed instead.
2.Aaliyah and Bryce both read 2 on call, both go off call, both commit. Name it and say why snapshot isolation allows it.Answer
A5B write skew. Each transaction updated a different object, so no write-write conflict fired and both snapshots looked safe.
3.Two clients read-modify-write one counter and the total rises by 1, not 2. Which anomaly and cheapest fix?Answer
Lost update. Use an atomic increment such as
UPDATE counters SET value = value + 1or a compare-and-set retry loop.4.A booking app checks for overlaps then inserts, twice concurrently. What breaks?Answer
A phantom: both checks pass on empty results, then both inserts land overlapping. Snapshot isolation needs serializable isolation or materialized conflict locks here.
Practice
- Gossip Glomers 6a: single-node transactions
Serve the
txn-rw-registerworkload on one node:./maelstrom test -w txn-rw-register --bin ~/go/bin/maelstrom-txn --node-count 1 --time-limit 20 --rate 1000 --concurrency 2n --consistency-models read-uncommitted --availability total - Gossip Glomers 6b: read-uncommitted under partition
Replicate writes to both nodes and run the base plus the partition case (
--availability total --nemesis partition). G0 (dirty write) is the only prohibited anomalyThe page states its checker cannot detect G0 anomalies, so a pass here is weaker than its label.
- Gossip Glomers 6c: read-committed under partition
Forbid G1a, G1b and G1c with abort code 30 (
txn-conflict):./maelstrom test -w txn-rw-register --bin ~/go/bin/maelstrom-txn --node-count 2 --concurrency 2n --time-limit 20 --rate 1000 --consistency-models read-committed --availability total --nemesis partitionRetype the command by hand: the page pastes a non-ASCII dash before
--nemesis.
You're done when
You write the four histories from memory, classify each with its Berenson name and say which one snapshot isolation admits.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 14 more in the section
- DDIA 2e - Chapters 7 and 8 Sharding and TransactionsMartin Kleppmann and Chris Riccomini · primary
Read both chapters completely. Build a decision table connecting access pattern, partition key, isolation, atomicity, failure and recovery before implementing either the partition map or workflow.
- A Critique of ANSI SQL Isolation Levels (Berenson et al., 1995)arXiv (Microsoft Research report) · required
Read the phenomena P0 to P3, the snapshot-isolation anomalies A5A (read skew) and A5B (write skew) and the summary tables. Cite these definitions, not the SQL-92 prose they correct.
- AlgoMaster System Design - Selected Sharding and Transaction ProblemsAlgoMaster · support
Use the sharding, consistent hashing, ACID, saga, idempotency and outbox lessons as vocabulary, and the problems Calculate Hash Shard Load, Count Keys Moved by Resharding, Merge Cross-Shard Top-K Results, Analyze Transaction Serializability, Build a Saga Compensation Order and Consume Outbox Events Idempotently and in Order as drills. The capstone must supply real persistence, fault history and load evidence.
Also in this section
- Weak Consistency: A Generalized Theory and Optimistic Implementations for Distributed Transactions (Adya, 1999)MIT LCS · support
Read the dependency-graph definitions of G0, G1 (a, b and c) and G2 and the levels PL-1 to PL-3 they define. They are the anomalies Elle checks on recorded histories.
- Serializable Snapshot Isolation in PostgreSQL (Ports and Grittner, 2012)arXiv · support
Read the dangerous-structure rule (two adjacent read-write antidependencies) from Cahill et al. and how PostgreSQL implements and limits it. False positives abort transactions, so measure abort rates.
- Sagas (Garcia-Molina and Salem, 1987)Cornell course copy · required
Read the whole paper: a saga is a sequence of transactions with compensating transactions, and compensation is application-defined. Name the steps whose effects cannot be compensated.
- Spanner: Google's Globally-Distributed Database (Corbett et al., 2012)Google (author copy) · support
Read TrueTime and the concurrency-control section (timestamps, commit wait, read-write and read-only transactions, two-phase commit over Paxos groups). TrueTime needs clock hardware, so emulate bounded uncertainty in simulation.
- Large-scale Incremental Processing Using Distributed Transactions and Notifications (Peng and Dabek, 2010)USENIX OSDI · support
Read the snapshot-isolation transaction protocol over Bigtable (primary lock, timestamp oracle) and notifications. Snapshot isolation still admits write skew.
- CMU 15-445 - Concurrency Control, Logging and RecoveryCarnegie Mellon Database Group · required
Follow Fall 2025 lectures 17 to 22, the transactions homework and the concurrency-control project where available. Reproduce lost update and write skew outside the project before claiming an isolation level.
- PostgreSQL 18 Documentation - Transaction Isolation and Explicit LockingPostgreSQL Global Development Group · required
Read Section 13.2 (Read Committed, Repeatable Read and Serializable with its serialization failures) and 13.3 (row locks and deadlocks). Reproduce write skew under Repeatable Read and its rejection under Serializable in the
postgres:18image. - The Internals of PostgreSQL - Concurrency ControlHironobu Suzuki · support
Read Chapter 5 Sections 5.5 to 5.9 (snapshots, visibility rules, preventing lost updates and serializable snapshot isolation) to see one real engine implement the anomalies and isolation levels you reproduce. Note the date you read it.
- MIT 6.5840 - Distributed Transactions and Lab 5 Sharded KVMIT PDOS · required
Use lecture 11 and Lab 5 for coordinator failure, shard ownership and migration. Treat the lab as the integrated advanced path; a smaller deterministic partition map is sufficient for the compulsory gate if time is constrained.
- DSLabs - Lab 4 Sharded Store and TransactionsUniversity of Washington (Ellis Michael) · support
Labs are Java 21 message-passing state machines tested on an emulated network and by model-checking search tests that print a minimal violating trace; run them with the
run-tests.pyscript and its--laband--partoptions. Lab 4 adds a shard master, shard movement and multi-key transactions across groups with two-phase commit and locking (Part 3): use it for the commit protocol across groups, which MIT Lab 5 does not exercise. - Gossip Glomers - Totally Available TransactionsFly.io and Jepsen · support
Each challenge runs locally under Maelstrom (v0.2.4; the pages were tested on 0.2.3) with its checker and, where the page says so, the partition nemesis; keep the run directory as the history. Do 6a to 6c (read-uncommitted, then read-committed transactions under partition). The 6b page says the checker cannot detect G0 anomalies, so a pass is weaker than its label.
- Building Distributed Systems - The Sharder and The CoordinatorBuild Distributed Systems · optional
Only the first three tasks of each track are free: in The Sharder, a shard controller, consistent hashing and configuration change; in The Coordinator, two-phase commit, coordinator failure and three-phase commit. Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.
- HLD Handbook - Sharding, Distributed Transactions and IdempotencyHLD Handbook · required
Read Part 2 database sharding, then Part 3 distributed transactions, idempotency and consistent hashing. Use Part 5 event patterns only for the chosen workflow design.
- Replicated Log and Stream Processor - Partition and Workflow SliceRoadmap-Final · support
Add partition routing, ownership epochs, rebalance, one cross-partition invariant and a durable transaction or saga path. Inject stale routes, coordinator death, duplicate steps and failed compensation.