Isolation Levels
Read uncommitted, read committed, snapshot isolation and serializable: which anomalies each one allows, how MVCC implements them, and why the same name means different things in different databases.
Overview
Why there are levels
Isolation decides what a transaction can see of other transactions running at the same time. Full isolation makes concurrent transactions behave as if they ran one after another. That costs waiting, aborts or both, so databases offer weaker levels that are faster but let some anomalies through.
The SQL standard names four levels and defines them by which anomalies they forbid. Think of them as a ladder, where each rung adds one guarantee to the rung below it.
- Read uncommitted may see data that other transactions have not committed yet.
- Read committed sees only committed data.
- Repeatable read, which many databases build as a snapshot, gives each transaction one stable view of the data.
- Serializable gives the same result as running the transactions one at a time. It is the only level that removes every anomaly.
Key concepts
- Dirty read
- Non-repeatable read
- Lost update
- Phantom read
- Write skew
- Snapshot isolation
- MVCC
- Serialization failure
Interview questions
- What is the difference between snapshot isolation and serializable isolation?
- How does MVCC work in PostgreSQL?
- Which isolation level would you choose for a banking application?
- Why does repeatable read mean different things in MySQL and PostgreSQL?
- How do you prevent lost updates?
Sign up free to read the full topic
More DDIA topics
- Event Streams and Message Brokers
- Fan-Out and the Twitter Timeline Problem
- Fault Tolerance in Stream Processing
- Faults and Partial Failures
- Graph Data Models
- Implementing Serializability
- Joins in Batch Processing
- Joins in Stream Processing
- Lambda and Kappa Architectures
- Leaderless Replication (Dynamo-Style)
- Linearizability
- LSM-Trees and SSTables
Start free on Cariara · Coding problems · System design studio