Courses / Databases for Backend Interviews / Chapter 20
Module 9 · Transactions, isolation and locking · Chapter 20 of 27
Isolation Levels and MVCC: Anomalies, Snapshots and Vacuum
Builds on Transactions: ACID, the Write-Ahead Log and Crash Recovery. Next up: Locks and Concurrency Control: Row Locks, Deadlocks and Optimistic Updates.
Part 1 · The anomalies
Why overlapping transactions need rules
Two riders tap the last seat on a bus at the same instant, and both get a confirmation. Isolation is the part of a database that decides what two overlapping transactions may see of each other.
The transactions chapter explained transactions and named isolation as the I in ACID. Isolation promises something specific when many transactions run at the same time, and it has a cost.
The ideal is serial execution: transactions run one after another, so each one sees a finished, settled world. A real server runs them at the same time, because making every request wait in a queue wastes the machine. Concurrent execution is only safe when its result matches some serial order of the same transactions. When it does not, the result is an anomaly: an outcome that no serial order could have produced.
A database lets you choose how careful it should be. Stricter levels forbid more anomalies, and they pay for it with waiting or with transactions that fail and must be run again. Before choosing a level you need names for what can go wrong.