ACID, isolation & MVCC
The guarantees that make concurrent databases trustworthy.
Why transactions are trustworthy
Transactions give the ACID guarantees:
- Atomicity — all statements commit or none do.
- Consistency — constraints hold before and after.
- Isolation — concurrent transactions don't see each other's half-finished work.
- Durability — once committed, it survives a crash.
Isolation levels trade strictness for concurrency: READ COMMITTED (Postgres default — you only see committed data), REPEATABLE READ (a stable snapshot for the whole transaction), and SERIALIZABLE (as if transactions ran one at a time). Looser levels permit anomalies — non-repeatable reads, phantom rows.
Postgres achieves this with MVCC (multi-version concurrency control): writers create new row versions instead of overwriting, so readers never block writers and writers never block readers. Explicit locks (SELECT ... FOR UPDATE) exist for when you must serialize a hot row, and two transactions waiting on each other cause a deadlock, which Postgres detects and aborts one of.