Isolation Levels in System Design Interviews: When to Use Them
When you design a data-intensive service, you must decide how concurrent operations interact. Isolation level is the contract that tells the system what a transaction can see while other transactions are in flight. It solves the problem of anomalies—situations where a client reads data that is later overwritten, leading to incorrect business logic.
The Problem Illustrated
Imagine a ride-sharing platform that matches drivers to riders. Two requests arrive at the same time for the same driver. If both transactions read the driver’s status as “available” and then each marks the driver as “assigned,” the driver could be double-booked. The isolation level you pick determines whether the second transaction sees the first transaction’s write before it commits, and whether it must abort and retry.
How Isolation Levels Work – Step by Step
- Begin Transaction – The client opens a logical unit of work.
- Read Phase – The system decides which version of each record the transaction can see, based on the chosen isolation level.
- Write Phase – Updates are stored in a private write-set.
- Validation / Conflict Detection – At commit time the system checks for conflicts with concurrent transactions.
- Commit / Abort – If no conflict, the changes become visible; otherwise the transaction aborts and the client retries.
Small Worked Example
Suppose we use Read Committed on a PostgreSQL-style DB:
- Tx1 starts, reads
balance = 100for account A. - Tx2 starts, reads the same
balance = 100. - Tx1 debits $10, writes
balance = 90, and commits. - Tx2 now debits $20 based on the stale value 100, writes
balance = 80, and tries to commit. - Read Committed does not stop this: Tx2’s write is accepted, the balance ends at 80 instead of 70, and Tx1’s debit is silently lost. This is the classic lost update.
If we had used Repeatable Read or Serializable on PostgreSQL, Tx2’s update would instead fail with a serialization error, and the client would retry and see balance = 90. Under Read Committed you prevent the lost update by locking the row with SELECT... FOR UPDATE or by writing the debit as one atomic UPDATE... SET balance = balance - 20.
Where Isolation Levels Appear in Classic Design Questions
| Design Question | Typical Spot for Isolation Discussion | Example Detail |
|---|---|---|
| Design a payment processing service | Data store choice and transaction handling | Explain why you would use Serializable for the ledger to avoid double-spend, but Read Committed for a reporting cache. |
| Design a social feed with fan-out writes | Consistency of fan-out writes across shards | Explain that pagination needs a cursor (keyset on post time and ID), not Repeatable Read, because each page is a separate request and a transaction cannot stay open between them; background analytics can tolerate eventual consistency. |
| Design an inventory system for an e-commerce site | Stock decrement logic | Discuss Snapshot Isolation (often implemented as Repeatable Read) to prevent overselling while keeping latency low. |
Trade-offs and the Alternative Interviewer May Probe
| Isolation Level | Guarantees | Performance Impact | Typical Use Cases |
|---|---|---|---|
| Read Uncommitted | Allows dirty reads | Minimal latency, high throughput | Analytics where stale data is acceptable |
| Read Committed | No dirty reads, but non-repeatable reads possible | Moderate latency, good throughput | Most OLTP workloads |
| Repeatable Read / Snapshot Isolation | No dirty or non-repeatable reads; the SQL standard allows phantoms here, while snapshot isolation (PostgreSQL's Repeatable Read) prevents them but allows write skew | Lock-based engines: more contention; snapshot engines: more aborts on conflicting writes | Banking, inventory, any scenario needing repeatable queries |
| Serializable | Full ACID, no anomalies | Highest latency, may require transaction aborts | Critical financial ledgers, strong consistency across distributed shards |
Interviewers often ask you to justify a level and then challenge you with the opposite extreme. For example, after you pick Read Committed for a payment service, they may ask: “What if two payments race on the same account? Could you get a lost update?” Your answer should be yes: a read-then-write under Read Committed can lose an update, so you either lock the row with SELECT... FOR UPDATE, write the change as one atomic UPDATE, or move that critical path to Repeatable Read or Serializable and retry on a serialization failure.
30-Second Pitch You Can Say Out Loud
"Isolation levels define how much a transaction can see of other concurrent work. They prevent anomalies like dirty reads or double-spends. In a payment service you’d usually pick Serializable for the ledger to guarantee no overspend, while using Read Committed for ancillary reads to keep latency low. The trade-off is that stronger isolation means more locking and higher latency, so you balance consistency needs against performance."
Common Mistakes Candidates Make
- Treating isolation as a DB-only concern. In distributed designs, a transaction that spans services gets no isolation from any single database: two-phase commit can provide it, while a saga provides none by default and needs countermeasures such as semantic locks or version checks.
- Confusing isolation with durability. Isolation only governs visibility of concurrent writes; durability is about persisting after a crash.
- Naming levels without context. Simply saying “We’ll use Serializable” without explaining why the business logic requires it looks rote.
- Ignoring the cost. Claiming that higher isolation is always better forgets the latency and throughput penalties, especially when scaling horizontally.
How to Practice This
- Study the worked design – Design a Relational Database like PostgreSQL, part of Pro ($10/month), one request path at a time.
- Draw your own diagram for a payment processing system on paper or a whiteboard. Sketch the transaction flow, label the isolation level for each store, and write a short note on why you chose it.
- Run a mock interview with a peer. Explain the isolation choice, then swap roles and ask each other about the trade-offs and alternative levels.
Questions people ask
What is the difference between Repeatable Read and Snapshot Isolation?
In lock-based engines such as SQL Server, Repeatable Read holds read locks until the transaction commits, preventing non-repeatable reads; PostgreSQL implements Repeatable Read as snapshot isolation. Snapshot Isolation gives each transaction a snapshot of the data as of its start time, achieving the same effect without locks, but can still allow write skew, where two transactions read the same rows and then make separate writes that together break a rule, unless the DB enforces true serializable isolation.
When is Read Uncommitted ever a good choice?
Read Uncommitted is suitable for low-latency analytics or monitoring where seeing uncommitted, possibly rolled-back data does not affect correctness, such as dashboards that display approximate metrics.
How do distributed systems enforce isolation without a single DB?
Two-phase commit or distributed locks can give isolation across stores. Sagas coordinate compensating actions instead and give no isolation by default, so other requests can see intermediate states unless you add semantic locks or version checks.
Can isolation levels be changed per request?
Yes, many databases let the client set the isolation level for each transaction, so a service can use a strong level for critical writes and a weaker level for read-only queries within the same service.