The "gold standard" is serializability: the concurrent result must equal some serial execution order. But locking everything to guarantee that is slow. So the SQL standard defines 4 levels, each banning a specific set of read anomalies.
Two transactions at READ COMMITTED. T1 reads bal (=100). T2 commits bal=200. T1 reads again.
Forecast: second read = ? · Is this an anomaly, and which?
Verify: second read = 200. This is a non-repeatable read — allowed at READ COMMITTED, banned at REPEATABLE READ.
Imagine the database is a shared notebook and people scribble in it at the same time.
READ UNCOMMITTED: you read someone's pencil scribble before they decide to keep it — they might erase it. Risky.
READ COMMITTED: you only read things people have inked in for real. But if you look at the same line twice, someone might have re-inked it in between, so it changes.
REPEATABLE READ: you take a photo of your page at the start and read from the photo, so lines you already looked at never change under you.
SERIALIZABLE: it's as if everyone takes strict turns — the final notebook looks exactly like if people went one by one. No surprises at all, but you wait more.
Dekho, database mein ek saath bahut saari transactions chal rahi hoti hain. Agar woh same rows ko touch karein bina kisi control ke, toh galat results aa sakte hain. Isolation levels ek dial hai jahan tum decide karte ho ki kitni "weirdness" allow karni hai concurrency badhane ke liye. Teen famous problems hain: dirty read (kisi ki uncommitted scribble padh li, jo baad mein rollback ho gayi), non-repeatable read (ek hi row do baar padhi, value badal gayi), aur phantom read (ek WHERE query do baar chalayi, naye rows aa gaye ya gayab ho gaye).
Char levels hain, weakest se strongest: READ UNCOMMITTED → READ COMMITTED → REPEATABLE READ → SERIALIZABLE. Har step neeche jaate hi ek anomaly band ho jaati hai. READ UNCOMMITTED sab kuch allow karta hai. READ COMMITTED sirf committed data dikhata hai (dirty read gone). REPEATABLE READ ek baar ka snapshot pakad leta hai, toh jo rows tumne padhi woh nahi badlengi (non-repeatable read gone). SERIALIZABLE poori tarah safe — result aisa hoga jaise transactions ek-ek karke chali ho (phantom bhi gone).
Yaad rakhne ka mnemonic: U-C-R-S order, aur D-N-P (Dirty, Non-repeatable, Phantom) ek-ek karke peel off hoti hain. Ek important baat: SERIALIZABLE ka matlab yeh nahi ki transactions literally line mein chalti hain — bas final result kisi serial order ke barabar hota hai, andar concurrency rehti hai (PostgreSQL toh SSI use karke conflicting transactions ko abort kar deta hai, jise tumhe retry karna padta hai).
Practical tip: hamesha SERIALIZABLE mat lagao — woh slow karta hai, deadlocks aur retries badhata hai. App ko jo anomaly actually nuksan karti hai, bas usse rokne wala lowest level choose karo. PostgreSQL default READ COMMITTED hai, MySQL InnoDB default REPEATABLE READ — yeh interview mein puchte hain!