categories.database Advanced
What Are the Four Transaction Isolation Levels and What Problems Do They Solve?
Transaction Isolation Levels
Four Anomaly Types
- Dirty Read: Reading uncommitted data from another transaction
- Non-repeatable Read: Reading the same row twice in one transaction yields different results (another transaction updated it in between)
- Phantom Read: Two queries in one transaction return different row counts (another transaction inserted/deleted rows)
- Lost Update: Two concurrent updates to the same row; one overwrites the other
Four Isolation Levels (low to high)
| Level | Dirty Read | Non-repeatable Read | Phantom Read |
|---|---|---|---|
| Read Uncommitted | Possible | Possible | Possible |
| Read Committed | Prevented | Possible | Possible |
| Repeatable Read | Prevented | Prevented | Possible |
| Serializable | Prevented | Prevented | Prevented |
Performance Trade-off
Higher isolation = lower concurrency performance (more locking)
Default Levels
- MySQL (InnoDB): Repeatable Read
- PostgreSQL: Read Committed
- Oracle: Read Committed
Interview bonus: PostgreSQL uses MVCC (Multi-Version Concurrency Control) for isolation without locks—readers don't block writers, giving better performance than traditional locking.
✦ AI Mock Interview
Type your answer and get instant AI feedback
Sign in to use AI scoring
