Medium👤 3-5 years👤 8-15 years 1 min read

Dirty read, non-repeatable read and phantom read — what are they and how do you prevent each?

Asked inAmazonMicrosoftbankingDeloitte
#dirty read#non-repeatable read#phantom read#isolation#anomalies
Report issue

⚡ Short Answer

Dirty read = seeing another txn's uncommitted data (prevented by READ COMMITTED). Non-repeatable read = same row returns different values within a txn (prevented by REPEATABLE READ). Phantom read = new rows appear for a re-run range query (prevented by SERIALIZABLE).

Coffee Chat Question

Concept Made Simple

Dirty read, non-repeatable read and phantom read — what are they and how do you prevent each?

🧠Mind Map Answer

Remember It Faster

Dirty readreads uncommitted data → READ COMMITTED
Non-repeatablerow value changes → REPEATABLE READ
Phantomnew rows in range → SERIALIZABLE

🔥What If?

Think Beyond the Expected

A balance check then debit double-spends under load — which anomaly, and the fix?

A read-then-write race (often a phantom/non-repeatable issue). Fix with SELECT ... FOR UPDATE to lock the row during the transaction, or optimistic locking with a version check, rather than just raising the global isolation level.

😂Real World

These anomalies underlie real money bugs (double-spend, oversell). Engineers pick the isolation level — or explicit locking — that blocks the specific anomaly their invariant needs.

🎯Interviewer's Expectation

Keywords they're listening for:

define all threewhich level prevents whichread-then-write raceFOR UPDATE / optimistic lockingMVCC nuance

⚠️Common Mistakes

  • Confusing non-repeatable read with phantom read
  • Relying on app logic for read-then-write safety
  • Assuming default isolation prevents all anomalies

Best Practices

  • Lock or version read-then-write critical sections
  • Match isolation to the invariant you must protect
  • Test concurrency paths under load

🔁Follow-up Questions

  • 1How does MVCC handle non-repeatable reads without locks?
  • 2What's a write skew and which level prevents it?
  • 3When do you reach for SELECT FOR UPDATE?

🧩Related Technologies

MVCCSELECT FOR UPDATE@Version (JPA)

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Transactions (SQL)
Interview question: "Dirty read, non-repeatable read and phantom read — what are they and how do you prevent each?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.
Open inChatGPTGeminiClaude

Was this answer helpful?

Support our platform by exploring our recommended products.

As an Amazon affiliate, purchases through these links may earn us a small commission — at no extra cost to you. It helps keep Full Stack Interview Guru free.

Related Questions