Isolation levels.
A dial deciding how much of everyone else’s half-finished typing your transaction gets to see.
Copy a figure out of a teammate’s spreadsheet while they are mid-edit, and your report can end up citing a number that never officially existed — they were about to delete that row. Databases live with this hazard thousands of times a second: transactions overlap, and someone must decide whether your read may see work that is not finished yet.
Isolation levels are that decision, made adjustable. At the strict end the database behaves as if transactions took turns one at a time, so nobody ever reads a draft. Each step looser allows more overlap and more speed, in exchange for one more kind of surprise.
- 1
Both writers believe they have the document to themselves; the database decides how true that gets to be.
- I cited that line!2
A dirty read: the line was never committed, so anything built on it rests on an event that never happened.
- 3
Read committed is the floor most databases default to — drafts are invisible, only saved edits count.
- 4
Repeatable read adds a promise: once your transaction reads a line, that answer holds until you finish.
- I counted three. Now four?5
Pinning lines you have read cannot stop brand-new rows slipping into a range you already counted.
- 6
Serializable buys certainty by spending concurrency — that idle editor is healthy, just made to queue.
One surprise retired per notch
Read the levels as a list of banned anomalies. Read committed bans dirty reads — seeing uncommitted work that may yet be rolled back. Repeatable read also bans the same row giving two answers within one transaction. Serializable bans phantoms, the new rows that appear in a range you already scanned, by making overlapping transactions behave like a queue. Each ban costs the database more bookkeeping: locks held longer or versions checked at commit, and either way fewer transactions running at once.
Match the level to the money
The skill is knowing which reads can afford a surprise. A comment feed showing a ten-second-old count harms nobody; run it loose and fast. A transfer between accounts must not act on a balance that might be rolled back mid-flight; run it serializable and accept the wait. Setting everything to the strictest level feels prudent but quietly throttles the whole system for the benefit of queries that never needed protecting.