A transaction groups multiple operations into one unit: either all commit or all roll back. Isolation level defines how much one transaction “sees” of other concurrent transactions — from dirty reads to full serializability.
Isolation levels (strongest to weakest)
flowchart TB
S[SERIALIZABLE\nNo phantoms, full isolation]
RR[REPEATABLE READ\nSame row read twice = same value]
RC[READ COMMITTED\nOnly see committed data]
RU[READ UNCOMMITTED\nDirty reads possible]
S --> RR --> RC --> RU
Level
Dirty read
Non-repeatable read
Phantom read
READ UNCOMMITTED
Yes
Yes
Yes
READ COMMITTED
No
Yes
Yes
REPEATABLE READ
No
No
Yes*
SERIALIZABLE
No
No
No
Anomalies explained
Dirty read — You see uncommitted changes from another transaction (they may roll back).
Non-repeatable read — You read a row twice in one transaction; it changes between reads because another txn committed.
Phantom read — You run the same query twice; new rows appear (or disappear) because another txn committed.
sequenceDiagram
participant T1 as Transaction 1
participant T2 as Transaction 2
participant DB as Database
T1->>DB: SELECT * FROM orders
T2->>DB: INSERT order (committed)
T1->>DB: SELECT * FROM orders (same query)
Note over T1: Phantom: new row appears
Default in many DBs is READ COMMITTED. Use REPEATABLE READ or SERIALIZABLE when you need consistent reads within a transaction; higher isolation can reduce concurrency (more locking).