What are the database isolation levels and what anomalies does each prevent?
Database isolation levels define how and when the changes made by one transaction become visible to other concurrent transactions. SQL defines four standard levels, each preventing an additional set of read anomalies at the cost of greater contention.
Read Uncommitted is the weakest level. A transaction can read changes made by other transactions that have not yet committed. This allows dirty reads -- reading data that may be rolled back, producing a view of the database that never actually existed. Almost never used in production.
Read Committed prevents dirty reads -- a transaction only sees data that has been committed. However, it allows non-repeatable reads: if transaction A reads a row, transaction B updates and commits that row, and A reads it again, A sees different values for the same row within the same transaction. This is the default in PostgreSQL and Oracle.
Repeatable Read prevents dirty reads and non-repeatable reads. Once a transaction reads a row, that row will return the same data for the duration of the transaction, even if another transaction modifies it. MySQL InnoDB uses MVCC (Multi-Version Concurrency Control) to implement this efficiently. However, phantom reads are still possible: a transaction running the same range query twice may see different sets of rows because another transaction inserted or deleted rows in that range. Repeatable Read is the default in MySQL InnoDB.
Serializable is the strongest level. Transactions execute as if they were run serially, one after another. This prevents all three anomalies. Implementations typically use range locks or predicate locks. PostgreSQL implements Serializable Snapshot Isolation (SSI), which uses MVCC with conflict detection rather than blocking locks, achieving full serializability with better concurrency than traditional lock-based approaches.
In practice, most applications use Read Committed or Repeatable Read. Choose Serializable only when correctness absolutely requires it -- for example, financial transactions where a race condition would produce double-spending.
| Isolation Level | Dirty Read | Non-Repeatable Read | Phantom Read | Default in |
|---|---|---|---|---|
| Read Uncommitted | Possible | Possible | Possible | Rarely used |
| Read Committed | Prevented | Possible | Possible | PostgreSQL, Oracle, SQL Server |
| Repeatable Read | Prevented | Prevented | Possible | MySQL InnoDB |
| Serializable | Prevented | Prevented | Prevented | Explicit opt-in; PostgreSQL SSI |
Candidate can name the four levels and associate dirty reads, non-repeatable reads, and phantom reads with the right levels, but cannot explain MVCC, how serializable is implemented, or what the real-world defaults are.
Candidate precisely defines all four anomalies, maps them to isolation levels, explains MVCC as the mechanism enabling non-blocking reads, names real database defaults, and discusses trade-offs between isolation and throughput.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment