How it works · 13 of 38 Core
What are database transactions and ACID?
All or nothing
Transactions & ACID: A transaction groups several writes into one all-or-nothing step: if anything fails before COMMIT, the database undoes every write in it, and once COMMIT is confirmed the change is already on disk and survives a crash.
Loading the animation…
Say it like this A transaction bundles several writes into one all-or-nothing step: if anything fails before COMMIT, every write is undone, and once COMMIT is confirmed the change survives a crash.
Under the hood — for builders
- The source's own example: one transfer, four updates
- PostgreSQL's tutorial moves $100.00 from Alice to Bob. Wrapped in BEGIN … COMMIT, all four happen or none:
- ACID, in one line each
- Atomic: all or nothing. Consistent: rules hold. Isolated: no half-views. Durable: survives a crash.
- Durable, concretely
- Each change is written to a log on disk (the write-ahead log) before COMMIT returns.
- Isolation: what others may see mid-transfer
- Stricter levels allow fewer surprises, at the cost of waiting or retrying:
- The four surprises
- Dirty: sees uncommitted data. Re-read: a row changes between reads. Phantom: new rows appear. Anomaly: impossible order.
- Watch out
- Without BEGIN, each statement commits alone. Stricter levels fail with "could not serialize access": retry.
- Sources
- PostgreSQL docs: "3.4. Transactions" and "13.2. Transaction Isolation" (version 18, read November 2026).
What happens in the transactions & ACID animation, step by step?
- Asha sends Ravi ₹500. To the database that is two separate writes: take ₹500 out of Asha's balance, then add ₹500 to Ravi's. The bank holds ₹2,800 in all.
- Your turn: the coin is on its way. Strike the database with lightning at any moment. When does a crash cost money?
- A crash between the two writes: ₹500 has left Asha and never reached Ravi. It is simply gone, and the bank's total drops from ₹2,800 to ₹2,300.
- Now wrap both writes in one transaction, BEGIN … COMMIT. Same strike, same moment: on restart the database undoes write 1, and the coin snaps back to Asha. All or nothing.
- This time the coin lands and the database says COMMIT, but only after the change is on disk. Strike again a second later: Ravi keeps his ₹500. Saved means saved.
- While the coin flies, an auditor totals the bank and sees ₹2,800, never the half-done state. That's ACID. It suits small rows like balances; where does a 4 GB video of the loan signing go? Next: object storage.
What everyday example explains transactions & ACID?
A shop counter that hands over the goods and takes the money as one deal. If the lights go out after the money is in the till but before the goods cross the counter, the shopkeeper hands the money back; once the receipt is printed, a power cut changes nothing.
Why should a team care about transactions & ACID?
Whenever one user action changes more than one row (an order and its stock, a payment and a ledger), put those writes in one transaction; and before choosing a database for money or inventory, check that it offers multi-row transactions and which isolation level it uses by default.