ACID Transactions Explained
The guarantees that keep a multi-step write from leaving a database in a half-finished, contradictory state.
Beginner
| Letter | Property | What it guarantees |
|---|---|---|
| A | Atomicity | All the writes in a transaction succeed, or none of them do — there's no partial state where the charge happened but the order didn't get created. |
| C | Consistency | A transaction only ever moves the database from one valid state to another — it can't leave data violating a defined rule, like an order referencing a restaurant ID that doesn't exist. |
| I | Isolation | Concurrent transactions don't see each other's half-finished work — the result is as if transactions ran one at a time, even though they didn't. |
| D | Durability | Once a transaction is confirmed committed, it survives a crash immediately after — it's on stable storage, not just in memory. |
BEGIN TRANSACTION;
UPDATE customers SET balance = balance - 24.50 WHERE id = 910;
UPDATE restaurant_inventory SET qty = qty - 1 WHERE item_id = 'pz_104';
INSERT INTO orders (customer_id, item_id, total) VALUES (910, 'pz_104', 24.50);
COMMIT;
qty = 1) at nearly the same instant. Without isolation, both transactions could read qty = 1, both decide the purchase is valid, and both commit — leaving qty = -1 and two customers who paid for food that doesn't exist.