Databases · Question 23 of 50
What are ACID transactions?
What they're checking
The fundamentals, with an example.
The answer
A transaction groups changes so they behave as one. Atomicity: all of it happens or none of it does (a transfer debits and credits, or neither). Consistency: it moves the database from one valid state to another, keeping its rules. Isolation: transactions running at the same time do not see each other's half-done work, to the degree the isolation level sets. Durability: once committed, it survives a crash, because it is in the write-ahead log on disk.
BEGIN;
UPDATE accounts SET balance = balance - 500 WHERE id = 1;
UPDATE accounts SET balance = balance + 500 WHERE id = 2;
COMMIT; -- or ROLLBACK if anything failedThe picture
A all or nothing the debit and the credit, or neither C the rules still hold constraints, foreign keys I no half-done reads isolation levels D survives a crash the write-ahead log
The follow-up they'll ask
How do you get this across two services?
Show the answer
Not with one local transaction. Use a saga (steps with compensating actions) or the outbox pattern, and design for eventual consistency.
Your progress stays on this device.