What's happening?
- A transfer needs two updates: take money from one account and add it to the other.
- Without a transaction, each update is saved on its own; a crash in between leaves the money half-moved.
- Inside a transaction, nothing is permanent until COMMIT. After a crash, the database rolls back anything not committed.
Where you'll meet it
Payments, bookings, stock levels, sign-ups that create several rows — anything where a half-done change would be wrong.
Common mistake
Calling external services (payment APIs, emails) inside a long transaction: locks are held while you wait, and a rollback cannot undo the email.
FAQ
What does ACID stand for?
Atomic (all or nothing), Consistent (rules still hold), Isolated (others don't see half-done work), Durable (committed means saved).
How does the database undo work after a crash?
It writes every change to a log before applying it. On restart it replays committed transactions and undoes the rest.
Do transactions prevent race conditions?
They help, but two transactions can still read the same old value. Locks (SELECT … FOR UPDATE) or constraints close the gap — see Race Condition.