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

Lab time 3.0 s
Starting…Starting…T3, Read committedT3Read committedstep 1 of 3Not used, IDLENot usedIDLElikes:42, = 1likes:42= 11 version
  • 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

What the transactions do
Workload
Isolation
Isolation level

A read sees the newest committed value at the moment it reads.

2

With 1, transactions never overlap.

Rows

RowCommitted valueVersions keptLocked by
likes:4211—

Versions kept: older values a running snapshot may still need. A locked row has a write that is not committed yet.

What just happened

  1. 2.5sError: T1 overwrote 1 like it never saw: a lost update.
  2. 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.