Relational Database Internals (Storage Engines, WAL, MVCC, ACID)
See how storage engines, WAL, and MVCC deliver ACID guarantees under concurrent readers and writers.
In plain words
Query text becomes an execution plan. Next, transaction locks and snapshot are established. Finally, redo records, remove dead versions.
Think of it like…
WAL is the journal written before moving inventory, and MVCC gives each observer a time-stamped inventory photograph instead of blocking the warehouse while someone rearranges shelves.
Where you’ve seen it
PostgreSQL writes a data change's WAL record durably before acknowledging COMMIT; readers select a tuple version visible to their snapshot, while vacuum later reclaims versions no transaction can need.
Words you’ll hear
- WAL
- Durable change records forced before dirty data pages so a crash can redo committed work without reading every previous state.
- MVCC
- Multi-version concurrency control, where readers see transaction-consistent tuple versions without waiting for ordinary writers.
- ACID
- Atomicity, consistency, isolation, and durability guarantees whose exact isolation failure modes are database-specific.
- Operational boundary
- Writers can stall while flushing WAL and MVCC can retain old row versions after long transactions, producing log pressure, table bloat, and confusing replication lag. Measure WAL volume, checkpoint cadence, replication slots, active snapshot age, and vacuum/autovacuum health; shorten transactions and tune I/O only after confirming which resource dominates.
Visual diagram
Theory & deep dive
WAL: the working mechanism
A relational engine records committed state through a write-ahead log, protects concurrent snapshots with locking and MVCC metadata, and exposes ACID behavior through a recovery and transaction protocol.
Query text becomes an execution plan. Transaction locks and snapshot are established, then WAL is forced before durable acknowledgement; this exposes the state governed by ACID.
PostgreSQL writes a data change's WAL record durably before acknowledging COMMIT; readers select a tuple version visible to their snapshot, while vacuum later reclaims versions no transaction can need.
Relational Database Internals: failure mode and production response
Writers can stall while flushing WAL and MVCC can retain old row versions after long transactions, producing log pressure, table bloat, and confusing replication lag.
Measure WAL volume, checkpoint cadence, replication slots, active snapshot age, and vacuum/autovacuum health; shorten transactions and tune I/O only after confirming which resource dominates. Track WAL fsync as "COMMIT waits for this durability point", and make Oldest snapshot visible to the dataset owner.
How it works, step by step
Step 1 of 41. Parse and plan
Query text becomes an execution plan. A relational engine records committed state through a write-ahead log, protects concurrent snapshots with locking and MVCC metadata, and exposes ACID behavior through a recovery and transaction protocol.
- WAL fsync
- COMMIT waits for this durability point
- MVCC
- Multi-version concurrency control, where readers see transaction-consistent tuple versions without waiting for ordinary writers.
When to use it & trade-offs
What it is
A relational engine records committed state through a write-ahead log, protects concurrent snapshots with locking and MVCC metadata, and exposes ACID behavior through a recovery and transaction protocol. PostgreSQL writes a data change's WAL record durably before acknowledging COMMIT; readers select a tuple version visible to their snapshot, while vacuum later reclaims versions no transaction can need.
Why it matters: Writers can stall while flushing WAL and MVCC can retain old row versions after long transactions, producing log pressure, table bloat, and confusing replication lag. Measure WAL volume, checkpoint cadence, replication slots, active snapshot age, and vacuum/autovacuum health; shorten transactions and tune I/O only after confirming which resource dominates.
When to reach for it
- See how storage engines, WAL, and MVCC deliver ACID guarantees under concurrent readers and writers.
- Choose WAL because it provides this capability: Durable change records forced before dirty data pages so a crash can redo committed work without reading every previous state.
- Keep evidence for WAL fsync at "COMMIT waits for this durability point" so the last production stage-Recover and reclaim - redo records, remove dead versions-remains testable.
When to avoid or be careful
- Writers can stall while flushing WAL and MVCC can retain old row versions after long transactions, producing log pressure, table bloat, and confusing replication lag.
- Do not conflate MVCC with WAL. The second concept contributes different behavior: Multi-version concurrency control, where readers see transaction-consistent tuple versions without waiting for ordinary writers.
- Release only after this guardrail is in place: Measure WAL volume, checkpoint cadence, replication slots, active snapshot age, and vacuum/autovacuum health; shorten transactions and tune I/O only after confirming which resource dominates.
WAL / MVCC / ACID - roles, limits, and operating cost
Strengths: Durable change records forced before dirty data pages so a crash can redo committed work without reading every previous state. A relational engine records committed state through a write-ahead log, protects concurrent snapshots with locking and MVCC metadata, and exposes ACID behavior through a recovery and transaction protocol.
Watch out: Writers can stall while flushing WAL and MVCC can retain old row versions after long transactions, producing log pressure, table bloat, and confusing replication lag.
Strengths: Multi-version concurrency control, where readers see transaction-consistent tuple versions without waiting for ordinary writers. In this workflow it supports: Log and mutate - WAL is forced before durable acknowledgement.
Watch out: The operating cost is real: can prevent vacuum from reclaiming dead tuples.
Strengths: Atomicity, consistency, isolation, and durability guarantees whose exact isolation failure modes are database-specific. Its output can be checked with Isolation.
Watch out: Operating guardrail: Measure WAL volume, checkpoint cadence, replication slots, active snapshot age, and vacuum/autovacuum health; shorten transactions and tune I/O only after confirming which resource dominates.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for WAL, and how would WAL fsync reveal it?”
- “Why is MVCC distinct from this behavior: atomicity, consistency, isolation, and durability guarantees whose exact isolation failure modes are database-specific?”
- Production clue: Writers can stall while flushing WAL and MVCC can retain old row versions after long transactions, producing log pressure, table bloat, and confusing replication lag.
- Design probe: Measure WAL volume, checkpoint cadence, replication slots, active snapshot age, and vacuum/autovacuum health; shorten transactions and tune I/O only after confirming which resource dominates.
Benchmarks & rules of thumb
- WAL fsync
- COMMIT waits for this durability point
- Oldest snapshot
- can prevent vacuum from reclaiming dead tuples
- Isolation
- the guarantee required by the application, not an automatic maximum-safety setting
Common mistakes & follow-ups
Common interview mistakes
- Writers can stall while flushing WAL and MVCC can retain old row versions after long transactions, producing log pressure, table bloat, and confusing replication lag.
- Reporting success from a job exit code without checking WAL fsync and Oldest snapshot.
- Treating this example as complete without replay, rollback, or access boundaries: PostgreSQL writes a data change's WAL record durably before acknowledging COMMIT; readers select a tuple version visible to their snapshot, while vacuum later reclaims versions no transaction can need.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: Durable change records forced before dirty data pages so a crash can redo committed work without reading every previous state.
- What does the recovery plan do when this occurs? Writers can stall while flushing WAL and MVCC can retain old row versions after long transactions, producing log pressure, table bloat, and confusing replication lag.
- When is WAL insufficient for Oldest snapshot, and what does adding MVCC cost in WAL fsync?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Relational Database Internals (Storage Engines, WAL, MVCC, ACID) with data engineer interview Q&A and hands-on practice.