Database Engineering · Keeping data correct
Isolation levels, locks and deadlocks
Transactions that run at the same time can read changing data and overwrite each other's work. Isolation levels and locks decide how much of that is allowed, and what it costs.
- Time18 min
- LevelDeveloper
- Experiments2 live
- Check6 questions






Priya's request BEGIN, then SELECT … FOR UPDATE: stock is 1, row locked.
Rahul's request runs the same SELECT … FOR UPDATE and waits for the lock.
Priya's request sets stock to 0, creates her order, and commits, releasing the lock.
Rahul's request gets the lock and reads the new value: stock is 0.
Rahul's request shows "sold out" and rolls back. One seat, one order.
Serializable every anomaly; may cancel a transaction with a serialization failure.
Read Committed (default) no dirty reads; each statement sees the latest commits.
Read Uncommitted accepted by PostgreSQL, but behaves exactly like Read Committed.