databases/database-transactions-why-moving-money-is-all-or-nothing.md

Database transactions: why moving money is all or nothing

Databases · 6 min read ·

Paying someone is really two changes in a database: take money from one account, add it to another. If the power dies between them, money vanishes.

A transaction bundles the changes so they happen all together or not at all. Pull the plug yourself in the interactive, then run real Python and SQLite code to see BEGIN, COMMIT and ROLLBACK keep the data safe.

Two account boxes, Ana with 70 and Ben with 50, and a crossed-out 30 on the arrow between them, showing a transfer that failed halfway

$ ls databases/

see all →