Question presented to candidate: "People say a relational database is ACID. What do the four letters actually mean, and can you show me one concrete thing the database does for each of them β say, for a bank transfer between two accounts?"
What a strong answer should cover:
- Atomicity: a transaction is all or nothing; if any step fails or the client calls
ROLLBACK, every change it made is undone (implemented with an undo log or old row versions) - Consistency: a committed transaction moves the database from one valid state to another; the database enforces declared rules (
CHECK,NOT NULL, foreign keys, unique keys) and the application owns the business invariants - Isolation: concurrent transactions do not see each other half-done; how strictly is the isolation level, and most engines default to something weaker than serializable
- Durability: once
COMMITreturns, the change survives a crash, because it was written to a write-ahead log (WAL) and flushed to disk first - Engine details that trip people up: in SQLite a failed statement does not abort the transaction (PostgreSQL does), and durability knobs such as
synchronous_committrade safety for speed
Code / implementation expected: Optional β a transfer wrapped in BEGIN ... COMMIT / ROLLBACK and a CHECK constraint is enough to illustrate the four properties.
Schema used by the examples: