F
Fatima Alam
Guest
Database Isolation Levels
Imagine youโre driving through a busy intersection.
Cars = transactions
Intersection = database
Traffic lights = isolation levels
If there are no rules, everyone just drives whenever they want โ chaos.
Thatโs why databases use Isolation Levels: rules that control how transactions move so data doesnโt crash into each other.

Think of a busy intersection.
Cars = transactions
Intersection = database
Traffic lights = isolation levels




Understanding isolation levels is key to writing correct and concurrent database applications.
This guide explains all levels with clear tables, anomalies, and transaction flows so that learning is fast and practical.
Isolation Level | Key Points | Concurrency | Isolation Strength |
---|---|---|---|
Read Uncommitted | Can read uncommitted (dirty) data. Dirty Read, Non-Repeatable Read, Phantom Read possible. | High | Low |
Read Committed | Reads only committed data. Prevents Dirty Read. Non-Repeatable & Phantom Read possible. | Medium-High | Medium-Low |
Repeatable Read | Reads held via shared locks until commit. Prevents Dirty & Non-Repeatable Read. Phantom Read possible. | Medium | High |
Serializable | Strictest. Uses range locks. Prevents Dirty, Non-Repeatable & Phantom Reads. | Low | Highest |

- - Dirty Read
โ You look at another carโs lane change before itโs even finished. (Reading uncommitted data).
- - Non-Repeatable Read
โ You check once, see a car in lane 1. You look again, and it has moved to lane 2. (Same row, different value).
- - Phantom Read
โ You look at the junction, count 2 cars. A moment later, new cars have appeared out of nowhere. (New rows magically appear).
Isolation Level | Dirty Read | Non-Repeatable Read | Phantom Read |
---|---|---|---|
Read Uncommitted | ![]() | ![]() | ![]() |
Read Committed | ![]() | ![]() | ![]() |
Repeatable Read | ![]() | ![]() | ![]() |
Serializable | ![]() | ![]() | ![]() |

Letโs watch how two cars (T1 & T2) drive through the intersection.
Time flows downward.
S-lock = car blocking a lane for looking.
X-lock = car blocking a lane for turning/changing.
Read Uncommitted (Dirty Read possible)
One car drives in without waiting, and another peeks too early.
Code:
| Time โ | T1 | T2 |
| ------ | --------------------- | ------------------ |
| t1 | BEGIN | |
| t2 | UPDATE Alice (X-lock) | |
| t3 | | READ Alice (dirty) |
| t4 | COMMIT | |
Read Committed (Non-Repeatable Read possible)
Cars wait for the green light, but switching lanes between looks is allowed.
Code:
| Time โ | T1 | T2 |
| ------ | ------------------------------------------- | --------------------- |
| t1 | BEGIN | |
| t2 | READ Alice (S-lock,<br>released after read) | |
| t3 | | UPDATE Alice (X-lock) |
| t4 | | COMMIT |
| t5 | READ Alice again (new value) | |
| t6 | COMMIT | |
Repeatable Read (Phantom Read possible)
Your lane is locked until you leave, but new lanes can still open.
Code:
| Time โ | T1 | T2 |
| ------ | ------------------------------------ | --------------------------------- |
| t1 | BEGIN | |
| t2 | READ Alice (S-lock held till commit) | |
| t3 | | UPDATE Alice (X-lock,<br>blocked) |
| t4 | COMMIT | |
| t5 | | UPDATE Alice (succeeds) |
| t6 | | COMMIT |
Serializable (No anomalies)
The traffic cop says: โOne batch at a time. Wait your turn.โ
Code:
| Time โ | T1 | T2 |
| ------ | ----------------------------------------------------------------------------- | ----------------------------- |
| t1 | BEGIN | |
| t2 | READ Accounts WHERE balance>1000<br>(S-lock + range lock<br>held till commit) | |
| t3 | | INSERT Bob(2000)<br>(blocked) |
| t4 | COMMIT | |
| t5 | | INSERT succeeds |
| t6 | | COMMIT |

Feature / Isolation | Read Uncommitted | Read Committed | Repeatable Read | Serializable |
---|---|---|---|---|
Dirty Read | Can read uncommitted (dirty) data ![]() | Prevents dirty read ![]() | Prevents dirty read ![]() | Prevents dirty read ![]() |
Non-Repeatable Read | Non-Repeatable read possible ![]() | Non-Repeatable read possible ![]() | Prevents Non-Repeatable read ![]() | Prevents Non-Repeatable read ![]() |
Phantom Read | Phantom read possible ![]() | Phantom read possible ![]() | Phantom read possible ![]() | Prevents Phantom read ![]() |
S-lock on read | None | Short-lived | Held till commit | Held + Range |
X-lock on write | Exclusive lock applied ![]() | Exclusive lock applied ![]() | Exclusive lock applied ![]() | Exclusive lock applied ![]() |
Concurrency | High | Medium-High | Medium | Low |
Isolation strength | Lowest | Medium-Low | High | Highest |
Continue reading...