1 ACID Properties In-Depth
TopBuilding on the ACID overview, let's examine how databases actually implement each guarantee.
Atomicity: Write-Ahead Logging (WAL)
Before writing data to disk, the database first writes the change to a transaction log (also called redo log). If a crash occurs mid-transaction, the database reads the log on restart and rolls back incomplete transactions. This is called Write-Ahead Logging.
Consistency: Constraint Enforcement
The database checks all constraints (PRIMARY KEY, FOREIGN KEY, CHECK, UNIQUE, NOT NULL) at the end of each statement (immediate mode) or at COMMIT (deferred mode). Any violation aborts the transaction.
Isolation: MVCC
Multi-Version Concurrency Control (MVCC) is how InnoDB and PostgreSQL handle isolation without excessive locking. Instead of blocking readers, the database keeps multiple versions of each row. Each transaction sees a consistent snapshot of the data as it was when the transaction started, even if other transactions are modifying it concurrently.
MVCC in practice: When Transaction A updates a row, InnoDB doesn't overwrite it. It creates a new version and keeps the old one in an undo log. Transaction B (which started earlier) still sees the old version. When both commit, the old version is garbage-collected. This is why readers don't block writers in InnoDB.
Durability: Double-Write Buffer
InnoDB uses a double-write buffer: before writing a data page to its final location on disk, it first writes it to a contiguous area. If a crash happens during the write, the data can be recovered from the double-write buffer. Combined with WAL, this guarantees committed data survives any crash.
Key Takeaways
- Atomicity is implemented via Write-Ahead Logging (WAL / redo log)
- Consistency is enforced by constraints checked at statement or commit time
- Isolation uses MVCC — multiple versions of rows so readers don't block writers
- Durability uses the double-write buffer + WAL to survive crashes