Isolation Levels and Concurrency: Real Tradeoffs
Understand the idea
Why isolation levels are practical engineering choices with real latency tradeoffs, not trivia.
The idea
The 'I' in ACID stands for , which controls how concurrent transactions see each other's changes. In an ideal world, every transaction would run completely alone as if nobody else was using the database. But running one at a time slows down a website. Databases therefore offer isolation levels that balance speed with data accuracy.
Databases prevent three common concurrency mistakes:
- : Transaction A reads changes made by Transaction B before B finishes. If B cancels, A worked with data that was never real.
- Non-Repeatable Read: Transaction A reads a row, Transaction B edits and saves that row, and A reads it again, seeing different values.
- : Transaction A counts matching rows, Transaction B adds a new row, and A counts again, seeing new 'phantom' rows.
Read Committed is the standard default for most modern databases. Modern systems use so readers never block writers and writers never block readers.
What changes
| Isolation Level | Dirty Reads | Non-Repeatable Reads | Phantom Reads | Concurrency Throughput |
|---|---|---|---|---|
| Read Uncommitted | Allowed (dangerous) | Allowed | Allowed | Maximum (no read locks) |
| Read Committed (Default) | Prevented | Allowed | Allowed | High (balance of safety and speed) |
| Repeatable Read | Prevented | Prevented | Allowed (in standard) | Moderate (locks/snapshots held) |
| Serializable | Prevented | Prevented | Prevented | Lowest (strict locks or abort on conflict) |
The command
Inspecting journal mode and isolation settings
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
The mistake
Check the result
Run the example to configure SQLite with Write-Ahead Logging (WAL) and verify that dirty reads remain disabled.
Guided challenge
Identify dirty read vulnerability
Update the function so it returns true only for 'read_uncommitted', accurately identifying which level allows dirty reads.
Identify dirty read vulnerability
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
EXPECTED RESULT
true false
Hints 0/1
Use all hints or make 3 failed checks (0/3).
Free exploration
Change this example and run it again. Each run is a new process. Nothing is saved.
Your variation
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 100 XP. You can always revisit it.