Transactions & Consistency
ACID Transactions
A transaction groups several operations so they succeed or fail as one unit — ACID is the set of guarantees that makes that safe.
A transaction bundles multiple reads and writes into a single unit — either the whole thing takes effect, or none of it does. ACID is the classic acronym for the guarantees a transactional database gives you.
Fig. 6 — The four ACID guarantees
Click a letter to see what it actually guarantees.
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 'a';
UPDATE accounts SET balance = balance + 100 WHERE id = 'b';
COMMIT;
If the process crashes between the two UPDATEs, atomicity guarantees the first one gets rolled back too — you never end up with money debited from one account and not credited to the other.