System Design AI

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

  1. Begin Transaction – The client opens a logical unit of work.
  2. Read Phase – The system decides which version of each record the transaction can see, based on the chosen isolation level.
  3. Write Phase – Updates are stored in a private write-set.
  4. Validation / Conflict Detection – At commit time the system checks for conflicts with concurrent transactions.
  5. 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 = 100 for 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 QuestionTypical Spot for Isolation DiscussionExample Detail
Design a payment processing serviceData store choice and transaction handlingExplain 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 writesConsistency of fan-out writes across shardsMention Repeatable Read to ensure a user sees the same set of posts during pagination, while allowing eventual consistency for background analytics.
Design an inventory system for an e-commerce siteStock decrement logicDiscuss Snapshot Isolation (often implemented as Repeatable Read) to prevent overselling while keeping latency low.

Trade-offs and the Alternative Interviewer May Probe

Isolation LevelGuaranteesPerformance ImpactTypical Use Cases
Read UncommittedAllows dirty readsMinimal latency, high throughputAnalytics where stale data is acceptable
Read CommittedNo dirty reads, but non-repeatable reads possibleModerate latency, good throughputMost OLTP workloads
Repeatable Read / Snapshot IsolationNo dirty or non-repeatable reads, possible phantom rowsHigher latency, more lock contentionBanking, inventory, any scenario needing repeatable queries
SerializableFull ACID, no anomaliesHighest latency, may require transaction abortsCritical 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, the isolation contract may be provided by a service layer (e.g., a saga orchestrator) rather than the database.
  • 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

  1. Study the worked design for a relational database like PostgreSQL in the System Design AI library, one request path at a time.
  2. Create your own canvas for a payment processing system. Sketch the transaction flow, label the isolation level for each store, and write a short note on why you chose it.
  3. 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?

Repeatable Read holds read locks until the transaction commits, preventing non-repeatable reads. 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?

They use two-phase commit, distributed locks, or saga patterns that coordinate compensating actions. The isolation contract is expressed at the service-level API rather than relying on a single database engine.

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.