How much can two transactions see of each other? Dirty reads, repeatable reads and the levels that stop them.
Isolation is the "I" in ACID. It answers one question: when two transactions run at the same time, how much of each other's work are they allowed to see?
A busy database runs thousands of transactions at once. If each one had to wait for the previous one to finish, nothing would be fast. So the database lets them overlap. Overlapping is where trouble starts: one transaction may read data that another is halfway through changing.
The SQL standard describes four isolation levels. Each level is defined by which problems it still allows.
| Level | Dirty read | Non-repeatable read | Phantom read |
|---|---|---|---|
| Read uncommitted | Possible | Possible | Possible |
| Read committed | Prevented | Possible | Possible |
| Repeatable read | Prevented | Prevented | Possible (in the standard) |
| Serializable | Prevented | Prevented | Prevented |
Two more problems matter in real systems but are not in that table: a lost update (two writers overwrite each other) and write skew (two transactions each check a rule, then both break it together).
| Problem | What happens | Example |
|---|---|---|
| Dirty read | You read data another transaction has not committed yet | T1 sets balance to 50 and rolls back. T2 read 50, which never existed. |
| Non-repeatable read | You read a row twice and get different values | T1 reads 100. T2 commits 50. T1 reads 50. |
| Phantom read | You run the same range query twice and get different rows | COUNT of open orders goes from 2 to 3. |
| Lost update | Two read-then-write sequences overwrite each other | Both add to 100. One +10 or +20 vanishes. |
| Write skew | Two transactions check a shared rule, then each change a different row, breaking the rule together | Both doctors leave, nobody is on call. |
| Technique | How it works | Cost |
|---|---|---|
| Locking | Readers and writers take locks; others wait for the lock to be released | Waiting, and the risk of deadlock |
| Snapshots (MVCC) | Each transaction reads a consistent snapshot of old versions, so readers do not block writers | Extra storage for old versions, and write conflicts still need handling |
| Serializable snapshot checks | Run on snapshots, track dependencies, abort a transaction if a dangerous pattern forms | Aborts that you must retry |
| Can it happen? | Read uncommitted | Read committed | Repeatable read | Serializable |
|---|---|---|---|---|
| Dirty read | ||||
| Non-repeatable read | ||||
| Phantom read | ||||
| Lost update | ||||
| Write skew |
A simplified teaching model. The first three rows follow the SQL standard table. Lost update and write skew are not in that table, so they show typical behaviour. Real databases differ: for example PostgreSQL never shows dirty reads and its repeatable read also stops phantoms, but it still allows write skew. Check your database documentation.
| Term | Meaning in easy words |
|---|---|
| Isolation | How much concurrent transactions can see of each other |
| Anomaly | A wrong-looking result that overlapping transactions can cause |
| Dirty read | Reading data that another transaction has not committed |
| Non-repeatable read | Reading the same row twice and getting different values |
| Phantom read | Running the same range query twice and getting different rows |
| Lost update | Two writers overwrite each other, so one change vanishes |
| Write skew | Two transactions each pass a check, then together break the rule |
| Snapshot | A consistent view of the data as it was at one moment |
| Serializable | The result is as if transactions ran one after another |
| Abort / retry | The database cancels a transaction, and you run it again |
| Deadlock | Two transactions each wait for a lock the other holds |
| Choice | We gain | We lose |
|---|---|---|
| Read committed | Speed, simple and common default | Non-repeatable reads, phantoms, lost updates unless you add locks |
| Repeatable read / snapshot | A stable view inside a transaction | Write skew can still happen, and old versions use space |
| Serializable | The strongest safety, simple to reason about | More blocking or aborts, lower throughput |
| Explicit row locks | Precise control where you need it | Waiting, and deadlocks if you lock in different orders |
| Optimistic version check | No locks held, good when clashes are rare | Retries when clashes are common |
| One big transaction | Everything is all-or-nothing | Long locks and more conflicts |