A transaction makes a group of changes all-or-nothing, and locks make concurrent transactions take turns; both are only as good as the boundaries and the order you choose.
Move ₹500 from Asha (balance ₹2,000) to Ben (balance ₹1,000). The app server crashes after the first UPDATE, restarts, and retries the transfer. Timings are an illustrative model.
App server
transfer code
Database
accounts table
Write-ahead log
on disk
Swipe the diagram sideways to see every column →
Where the time goes
8 ms total
Move ₹500 from Asha (balance ₹2,000) to Ben (balance ₹1,000). The app server crashes after the first UPDATE, restarts, and retries the transfer. Timings are an illustrative model.
Illustrative timings. Real numbers vary with distance, network quality and server load.