Transaction Isolation Levels
Transaction isolation is the I in ACID. It defines what one transaction can see of another transaction’s in-progress work. The choice of isolation level is one of the most consequential decisions in transactional system design — and one of the most under-discussed.
This lesson covers the four standard SQL isolation levels, the anomalies each allows, and practical guidance for choosing.
The Anomalies
Transaction isolation is defined by which anomalies can occur. Here are the classic ones, in order of severity:
The Four Standard Isolation Levels
Defined by SQL standard, but with implementation-specific quirks.
What each level prevents
| Level | Dirty read | Non-repeatable | Phantom | Lost update | Write skew |
|---|---|---|---|---|---|
| Read Uncommitted | ❌ | ❌ | ❌ | ❌ | ❌ |
| Read Committed | ✅ | ❌ | ❌ | ❌ | ❌ |
| Repeatable Read | ✅ | ✅ | ❌ (1) | varies (2) | ❌ |
| Serializable | ✅ | ✅ | ✅ (3) | ✅ (3) | ✅ (3) |
(1) The SQL name does not promise to stop phantoms. PostgreSQL does stop them at Repeatable Read. (2) Lost-update behavior is implementation-defined: PostgreSQL’s Repeatable Read allows a lost update, MySQL’s prevents it. (3) Oracle’s SERIALIZABLE is snapshot isolation and still allows write skew. Some systems have no true serializable level at all.
Read Committed and Repeatable Read are often the same MVCC engine with a different snapshot rule. Under Read Committed the snapshot refreshes on every statement, so a later statement sees rows committed since the previous one. Under Repeatable Read the snapshot is taken once and held for the transaction. The older lock protocol did the same split: write locks held until commit, read locks held only for the statement (Read Committed) or until commit (Repeatable Read).
A lost update on PostgreSQL Repeatable Read looks like this. Two transactions read a balance of 1000. Each adds 200 and writes 1200. The second commit replaces the first, and one deposit is gone; 1400 was the right result. One statement does the arithmetic inside the engine, so the race does not arise:
UPDATE accounts SET balance = balance + 200 WHERE id = 1;
The hole opens when the read and the write are separate statements. SELECT FOR UPDATE, a dedicated lock row, or an advisory lock closes lost updates, phantoms, and write skew while you stay on Repeatable Read.
On PostgreSQL 9.1+ the serializable level records read and write dependencies and aborts one transaction when that graph has no serial order. Workloads often land about 10-30% slower than Read Committed, and the application retries aborts, including false positives. SQL Server uses range locks for the same guarantee. CockroachDB and FoundationDB treat serializable as the ordinary level. Oracle’s level of the same name still allows write skew.
Implementation Differences
The SQL standard gives names; databases implement them differently.
The Snapshot Isolation Trap
Most databases’ “Repeatable Read” or “Snapshot Isolation” is actually weaker than true serializable. The classic example is write skew:
Constraint: "At least one doctor must be on call."
T1 reads: Alice on call, Bob on call. (count = 2)
T1 thinks: "OK, I can take Alice off — Bob will still be on call."
T1 writes: Alice off.
T2 reads: Alice on call, Bob on call. (count = 2) -- snapshot from before T1 commit
T2 thinks: "OK, I can take Bob off — Alice will still be on call."
T2 writes: Bob off.
Result: nobody on call. Constraint violated.
Both transactions read a consistent snapshot. Both wrote based on that snapshot. Neither saw the other. Snapshot isolation can’t catch this — only true serializable can.
Practical Guidance
Optimistic vs. Pessimistic Concurrency
Beyond isolation levels, you have two strategies for handling conflict:
A typical optimistic update:
SELECT id, value, version FROM accounts WHERE id = 42;
-- compute new_value based on value
UPDATE accounts SET value = new_value, version = version + 1
WHERE id = 42 AND version = old_version;
-- if 0 rows updated, someone else modified it; retry
Multi-Statement Transactions in Distributed Systems
For systems spanning multiple databases or services, full ACID transactions aren’t viable. Patterns:
Recap
- Isolation defines what one transaction sees of another’s in-progress work.
- The classic anomalies: dirty read, non-repeatable read, phantom, lost update, read skew, write skew.
- Standard isolation levels: Read Uncommitted, Read Committed (default), Repeatable Read, Serializable.
- Same level name behaves differently across databases — always check your DB’s specific semantics.
- Snapshot isolation isn’t true serializable — write skew is the classic gotcha.
- Pick by use case: Read Committed for most reads, Repeatable Read for reports, Serializable for invariant-critical updates, FOR UPDATE for hot rows.
- For distributed systems: outbox, sagas, idempotency keys, ETags.