Lab · Building blocks
Transactions & isolation levels
Up to three transactions run at the same time against a few rows. Pick an isolation level and watch which mistakes it lets through: lost updates, dirty reads, wrong totals and write skew. Serializable stops them all, and its price is aborted transactions.
Try it
- Starting… — healthy
- T3 — Read committed — healthy — step 1 of 3
- Not used — IDLE
- likes:42 — = 1 — healthy — 1 version
- Read
- Write
- Commit
- Abort
Committed
2
Aborted
0
Lost updates
1
Problem:
Committed likes
2
stored: 1
Numbers add up:3 started = 2 committed + 0 aborted + 1 runningThe lab checks this sum as it runs, so a counting mistake would show here.
Controls
Follow a request
Pause to pick a request that is on screen.
Rows
| Row | Committed value | Versions kept | Locked by |
|---|---|---|---|
| likes:42 | 1 | 1 | — |
Versions kept: older values a running snapshot may still need. A locked row has a write that is not committed yet.
What just happened
- 2.5sError: T1 overwrote 1 like it never saw: a lost update.
- 0.0sInfo: Two people like a post, at read committed.
What this model simplifies
- Time is slowed so you can watch each step. Real transactions like these take a few milliseconds.
- Every write locks its row until the transaction ends, at every level, as most databases do.
- Serializable here uses snapshot reads plus a check at commit: it aborts a writer if anything it read changed meanwhile. Real databases use finer checks, or locks, and abort less often.
- Aborted transactions are not retried here. A real app retries them, which costs more time.
- A transfer moves money with two atomic updates (balance = balance − 100), so transfers alone never lose money.