Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 21/ 160
02. Advanced SQL & Relational Databases

Relational Database Internals (Storage Engines, WAL, MVCC, ACID)

See how storage engines, WAL, and MVCC deliver ACID guarantees under concurrent readers and writers.

AdvancedWAL · MVCC · ACID3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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

Loading interactive 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.

Relational Database Internals in one concrete design

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.

Key takeaway: 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

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.

Key takeaway: 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.

How it works, step by step

Step 1 of 4
WAL

1. 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.

query text becomes an execution plan
Key numbers at this step
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

WAL
Best for: Durable change records forced before dirty data pages so a crash can redo committed work without reading every previous state.

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.

MVCC
Best for: Multi-version concurrency control, where readers see transaction-consistent tuple versions without waiting for ordinary writers.

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.

ACID
Best for: Atomicity, consistency, isolation, and durability guarantees whose exact isolation failure modes are database-specific.

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?
Interview tip: Lead with the data path and failure boundary: 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. Then make the answer operational: 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.

Knowledge check

Loading quiz

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.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
CI/CD Workflows for Data Engineering (GitHub Actions, Linting with Ruff)
Next topic
PostgreSQL Architecture, Schemas, Data Types & Constraints