What are transaction isolation levels, and what anomalies do they prevent?
What they are really testing: Whether you know the levels (read committed, repeatable read, serializable) and the anomalies (dirty, non-repeatable, phantom reads), and the isolation-versus-concurrency trade-off.
A real interview question
What are transaction isolation levels, and what anomalies do they prevent?
What most people say
drag me
“Isolation levels control how transactions see each other; serializable is the safest so use that.”
It knows serializable is strongest but ignores the cost. Always using serializable kills concurrency. The point is matching the level to the anomalies you must prevent versus the throughput you need.
The follow-ups they ask next
What is the difference between a non-repeatable read and a phantom read?
Non-repeatable: a row you already read changes value when you read it again. Phantom: re-running a range query returns new rows that were inserted. Repeatable read stops the former; serializable stops both.
Why not just use serializable everywhere?
It is the most expensive, more locking/contention, or more transaction aborts to retry in MVCC systems, which reduces throughput. Use the lowest level that is correct, usually read committed, and escalate only where needed.
What the interviewer is listening for
- Knows the anomalies + which level stops each
- Knows read committed is a common default
- Articulates the isolation/concurrency trade-off
What sinks the answer
- "Just use serializable"
- Cannot name the anomalies
- No notion of the concurrency cost
If you genuinely do not know
Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.
“Isolation levels [trade strictness for concurrency]. Anomalies: [dirty read (see uncommitted), non-repeatable read (row changes between reads), phantom (new rows appear)]. Levels: [read uncommitted -> read committed (common default, no dirty) -> repeatable read (no non-repeatable) -> serializable (full, no phantoms)]. Higher = [more locking/aborts], so [pick the lowest correct level, usually read committed].”
Keep going with databases
Foundation
What is a database index, how does it speed up queries, and what does it cost?
Foundation
What are the ACID properties of a database transaction?
Foundation
What is normalization, and what are primary and foreign keys?
Junior
A query is slow in production. How do you diagnose and fix it?
Junior
Why is database connection pooling important, especially at scale?
Junior
How do read replicas help scale a database, and what is replication lag?
Knowing the answer is not the same as recalling it under pressure
Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.
Start free