What Are Transaction Isolation Levels?
Isolation Levels vs Anomalies
| Isolation Level | Dirty Read | Non-Repeatable | Phantom | Write Skew |
|---|---|---|---|---|
| Read Uncommitted | Possible | Possible | Possible | Possible |
| Read Committed | Prevented | Possible | Possible | Possible |
| Repeatable Read | Prevented | Prevented | Possible* | Possible |
| Serializable | Prevented | Prevented | Prevented | Prevented |
Read Uncommitted
The weakest level. Transactions can see uncommitted changes from other transactions (dirty reads). If Transaction B modifies a row then rolls back, Transaction A may have already acted on that phantom value. Rarely used in production because it provides no meaningful guarantee.
Read Committed
Guarantees data read was committed at the moment of reading. Successive reads of the same row within one transaction may return different values if another transaction commits between them (non-repeatable reads). The default in most databases. Safe for OLTP (Online Transaction Processing) workloads where each query is independent. Locks are held only during statement execution, minimizing contention.
Repeatable Read
If you read a row once, subsequent reads within the same transaction return identical data, even if other transactions commit updates. Implemented using MVCC (Multi-Version Concurrency Control): the database keeps snapshots of data at transaction start time. New rows inserted by concurrent transactions may still appear (phantom reads). Some databases prevent phantoms using gap locks (locks on ranges between existing index keys).
Serializable
The strongest level. Guarantees that concurrent transactions produce results identical to some serial execution order. Prevents all anomalies including write skew. Implemented via locking (2PL), optimistic validation, or dependency tracking. The performance cost is significant: higher abort rates under contention, longer lock waits, or commit delays. Use for critical paths where correctness is non-negotiable (financial transactions, inventory reservations).