Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Define dirty reads, non-repeatable reads and phantom reads with a short example of each, and say which standard isolation level is the first to prevent each one.

Try it yourself

Isolation levels: what a second read sees

Step through two transactions and see exactly when read committed and repeatable read give different answers.

Read this example as text

T1 at read committed

  1. T1 begins. Transaction T1 starts with isolation level READ COMMITTED. The row holds balance 100.
  2. T1 reads the balance. T1 reads 100. Under read committed each statement looks afresh at what is committed when the statement starts.
  3. T2 changes the row. A second transaction, T2, sets the balance to 150 but has not committed. The database keeps both versions: 100 is still the committed one.
  4. T1 reads again, before T2 commits. T1 reads 100 again. Neither level shows another transaction's uncommitted change, so there is no dirty read. T1 does not wait for T2 either.
  5. T2 commits. T2 commits. The committed balance is now 150.
  6. T1 reads a third time. T1 reads 150. The same query, inside one transaction, returned 100 and then 150. This is a non-repeatable read, and read committed allows it.
  7. T1 commits. T1 ends. A transaction that starts now reads 150 at either level.

T1 read 100, 100, then 150: a non-repeatable read.

T1 at repeatable read

  1. T1 begins. Transaction T1 starts with isolation level REPEATABLE READ. The row holds balance 100.
  2. T1 reads the balance. T1 reads 100. Under repeatable read this first read fixes T1's snapshot: T1 will keep seeing the data as it was committed at this moment.
  3. T2 changes the row. A second transaction, T2, sets the balance to 150 but has not committed. The database keeps both versions: 100 is still the committed one.
  4. T1 reads again, before T2 commits. T1 reads 100 again. Neither level shows another transaction's uncommitted change, so there is no dirty read. T1 does not wait for T2 either.
  5. T2 commits. T2 commits. The committed balance is now 150.
  6. T1 reads a third time. T1 still reads 100. Its snapshot was fixed at its first read, so T2's commit is invisible to it. The read is repeatable.
  7. T1 commits. T1 ends. A transaction that starts now reads 150 at either level.

T1 read 100 three times: its reads were repeatable.

What this example leaves out
  • Modelled on PostgreSQL and MySQL InnoDB, where a plain SELECT reads a snapshot and never waits for a writer.
  • SQL Server's default read committed uses locks instead: there, T1's second read would wait for T2 to finish.
  • Only reads are compared. What happens when T1 also writes the row (a lost update, or an error in PostgreSQL) is not modelled.

A dirty read is reading another transaction's uncommitted change, which may then be rolled back; READ COMMITTED is the first level that prevents it. A non-repeatable read is reading the same row twice and getting different values because another transaction updated and committed it in between; REPEATABLE READ is the first to prevent it. A phantom read is running the same range query twice and seeing new rows another transaction inserted; the SQL standard allows phantoms at REPEATABLE READ and forbids them only at SERIALIZABLE, although real databases differ, PostgreSQL's REPEATABLE READ showing no phantoms at all.

Why this question is asked

Isolation levels are a setting most developers leave at the default, until a report shows numbers that do not add up or a check passes that should have failed. The three classic read phenomena are the vocabulary for talking about those bugs. Interviewers ask about them to check that we can describe each one precisely, map it to the levels, and know where real databases differ from the textbook. In this answer, we will recap isolation levels, go through each phenomenon with a two-session example, map them to the standard levels, see how PostgreSQL and MySQL actually behave, and note what the standard list leaves out.

1A Quick Recap of Isolation Levels

When transactions run at the same time, the isolation level decides how much one can see of what others are doing. The SQL standard defines four levels, READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ and SERIALIZABLE, in terms of which phenomena each must prevent. A phenomenon, also called an anomaly, is an effect of concurrency that could not happen if the transactions ran one after another.

In the examples below, T1 and T2 are two concurrent transactions, and accounts has a row with id 1 and balance 100.

2Dirty Read

A dirty read happens when T1 reads a change that T2 has made but not committed. If T2 then rolls back, T1 has used data that never existed.

SQL
-- T2 -- T1 (READ UNCOMMITTED, where supported)
BEGIN;
UPDATE accounts SET balance = 0 WHERE id = 1;
SELECT balance FROM accounts WHERE id = 1; -- 0 (dirty)
ROLLBACK; -- the 0 never existed
-- T1 already declined a payment based on 0

Notice the danger: T1's decision rests on a value that was never committed. READ COMMITTED is the first level that prevents this, because a transaction then only sees data that other transactions have committed; T1 would read 100.

3Non-Repeatable Read

A non-repeatable read happens when T1 reads the same row twice and gets different values, because T2 updated the row and committed between the two reads. Each value T1 saw was committed, so this is not a dirty read, but T1's picture of the row changed in the middle of its work.

SQL
-- T1 (READ COMMITTED) -- T2
BEGIN;
SELECT balance FROM accounts WHERE id = 1; -- 100
UPDATE accounts SET balance = 40 WHERE id = 1;
COMMIT;
SELECT balance FROM accounts WHERE id = 1; -- 40: same row, different value
COMMIT;

A report that reads a balance at the start and again at the end may then show totals that do not match. REPEATABLE READ is the first standard level that prevents this: once T1 has read a row, re-reading it in the same transaction returns the same value.

4Phantom Read

A phantom read is about sets of rows rather than one row. T1 runs the same range query twice, for example all orders with status 'NEW', and the second time sees rows that T2 inserted, or no longer sees rows T2 deleted, and committed in between. The new rows are the phantoms.

SQL
-- T1 -- T2
BEGIN ISOLATION LEVEL REPEATABLE READ;
SELECT count(*) FROM orders WHERE status = 'NEW'; -- 7
INSERT INTO orders (id, status) VALUES (900, 'NEW');
COMMIT;
SELECT count(*) FROM orders WHERE status = 'NEW'; -- standard allows 8; PostgreSQL returns 7
COMMIT;
What the SQL standard requires
LevelDirty readNon-repeatable readPhantom read
READ UNCOMMITTEDpossiblepossiblepossible
READ COMMITTEDpreventedpossiblepossible
REPEATABLE READpreventedpreventedpossible
SERIALIZABLEpreventedpreventedprevented
The standard sets minimums; databases may prevent more.

Notice why REPEATABLE READ in the standard does not stop this: it protects rows T1 has already read, and row 900 did not exist when T1 first looked. The standard forbids phantoms only at SERIALIZABLE.

5How Real Databases Differ

The standard defines minimum guarantees, and real databases often give more. PostgreSQL never allows dirty reads: asking for READ UNCOMMITTED gives READ COMMITTED behaviour. Its REPEATABLE READ is implemented as snapshot isolation: the transaction reads from a snapshot taken at its first statement, so it sees neither changed values nor new rows from later commits, which is why the example above returns 7. PostgreSQL's REPEATABLE READ therefore shows no phantoms, even though the standard would allow them.

MySQL's InnoDB, whose default is REPEATABLE READ, also uses a snapshot for ordinary reads, so plain SELECTs do not see phantoms either. Locking reads such as SELECT ... FOR UPDATE read the latest committed rows and use next-key locks, which lock index ranges, so other transactions cannot insert into the range being read. SQL Server, by contrast, uses locking for its standard levels unless snapshot options are enabled. So when someone names an isolation level, the next question is always: in which database?

6What the Standard List Leaves Out

The three phenomena were defined when isolation was mostly implemented with locks, and the list turned out to be incomplete. A lost update, where two transactions read the same value and both write back a result based on it, so one change is lost, is not one of the three. Write skew, where two transactions read overlapping data and each updates a different row, together breaking a rule such as 'at least one doctor on call', is not either, and snapshot isolation allows it. Later research on isolation pointed this out and defined these anomalies, which is why 'REPEATABLE READ prevents the three phenomena' does not mean 'REPEATABLE READ is safe'.

7Follow-up questions

Which anomalies does snapshot isolation still allow?

Mainly write skew: two transactions read the same rows, each decides based on its snapshot, and each writes a different row, so a rule spanning those rows breaks. There is also a read-only anomaly, where a read-only transaction sees a state that no serial order could produce. PostgreSQL's REPEATABLE READ prevents lost updates on the same row, failing the second writer with a serialization error, but write skew needs SERIALIZABLE or explicit locking.

Which isolation level should a typical service use?

READ COMMITTED, the PostgreSQL default, is right for most work, combined with constraints and explicit locks such as SELECT ... FOR UPDATE where a decision depends on what was read. Use REPEATABLE READ for consistent multi-query reports, and SERIALIZABLE for rules across rows that are hard to lock, with retries on serialization failures.

Does MySQL's REPEATABLE READ prevent lost updates?

Not for plain reads followed by writes based on them. Two transactions can each read a balance from their snapshot and each write back a computed value, and InnoDB will apply both, losing one. Using SELECT ... FOR UPDATE, an atomic UPDATE such as balance = balance - 100, or SERIALIZABLE avoids it.

8Conclusion

In this answer, we saw that a dirty read uses another transaction's uncommitted change and is prevented from READ COMMITTED upward, a non-repeatable read sees a row change between two reads and is prevented from REPEATABLE READ upward, and a phantom read sees new rows in a repeated range query and is forbidden by the standard only at SERIALIZABLE. Real databases differ: PostgreSQL never allows dirty reads and its snapshot-based REPEATABLE READ shows no phantoms, and the standard's list misses anomalies such as lost update and write skew.

What to say in the interviewAbout 90 seconds aloud

Open with

A dirty read is when my transaction reads a change another transaction made but has not committed. If that transaction rolls back, I acted on data that never existed.

Then, if they want more

READ COMMITTED is the first standard level that prevents it. A non-repeatable read is when I read the same row twice in one transaction and get different values, because another transaction updated it and committed in between, for example a balance of 100 and then 40. REPEATABLE READ is the first level that prevents that.

A phantom read is about ranges: I run the same query twice, say all orders with status NEW, and the second time I see rows another transaction inserted and committed. The standard still allows phantoms at REPEATABLE READ, because it only protects rows I already read, and forbids them only at SERIALIZABLE. Real databases differ from the standard, though.

PostgreSQL never allows dirty reads, even if you ask for READ UNCOMMITTED, and its REPEATABLE READ is snapshot isolation, so the whole transaction sees one snapshot and no phantoms. InnoDB uses snapshots for plain reads too, and next-key locks for locking reads.

And the standard list is incomplete: lost updates and write skew are not among the three phenomena, and snapshot isolation still allows write skew, which is why SERIALIZABLE or explicit locking is needed for rules that span several rows.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Define dirty reads, non-repeatable reads and phantom reads with a short example of each...": https://scrivio-interview-library.netlify.app/databases/acid-and-isolation/81a3655faf/