SoloMedium5m
The Double-Booking Disaster
CRITICAL — financial ledger mismatch
CFO Office: User alice_99 had $1,000. Two concurrent $600 withdrawals both returned SUCCESS. Final balance: $400 — the company lost $600.
The trap: Read-modify-write without checking version. Both threads read $1000, both write $400.
Your task
Fix `withdraw()` in `ledger.py`: use optimistic locking — pass version from get_account() into db.update_balance(); return FAILED on version conflict.
Book: SELECT FOR UPDATE · Prod: version column optimistic lock without row locks.
Skills you'll prove
pythonconcurrencyoptimistic-lockingdatabasefintechbook-vs-prod