Lesson 18 · Transactions & concurrency
ACID & isolation levels
The guarantees a transaction gives — and how much it hides from its neighbours.
Your win: define ACID and name Postgres's three isolation levels with what each one guarantees — a staple interview question, built on the MVCC snapshots from Lesson 6.
ACID in one line each
Atomicity
All-or-nothing — commit together or roll back together (Lesson 4).
Consistency
Constraints (Lesson 2) always hold; a tx moves the DB from one valid state to another.
Isolation
Concurrent transactions don't corrupt each other — the subject of this part.
Durability
Committed changes survive a crash — via the WAL (Lesson 8).
Isolation levels: how much you see of others
An isolation level controls which concurrent changes your transaction can observe. Under the hood it's just which MVCC snapshot you read from (Lesson 6). Postgres offers three usable levels:1
| Level | Sees | Prevents |
|---|---|---|
| Read Committed (default) | a fresh snapshot per statement of committed data | dirty reads |
| Repeatable Read | one snapshot fixed at transaction start | + non-repeatable & phantom reads |
| Serializable | as if transactions ran one at a time | + write skew (all anomalies) |
database.ExecInTx runs at the default Read Committed (plain
BEGIN). The only isolation-aware helper is
ExecInTxWithRetry, which retries on SerializationFailure
(SQLSTATE 40001) — the error a Serializable transaction
raises when it can't be made to look serial. So the retry helper exists specifically for
code that opts into the strictest level (Lesson 20).
PostgreSQL — Transaction Isolation
The authoritative chapter on the three levels, the anomalies each prevents, and how they map onto MVCC snapshots.
Check yourself (from memory)
Q1. Postgres's default isolation level is…
Q2. A higher isolation level gives you…
Q3. Isolation levels are built on top of…
ExecInTx = Read Committed;
ExecInTxWithRetry retries 40001.