FullStack AI Hub
Studio
DB & Data Pipelines · 01. Storage & Execution
10 min
6 steps
Intermediate

WAL, Buffer Pool & MVCC

Step inside PostgreSQL and InnoDB: sequential write-ahead logs, dirty-page buffer pools, snapshot MVCC, and vacuum bloat.

DB & Data Pipelines01. Storage & ExecutionLesson 1 of 2
10 minIntermediate6 steps

WAL, Buffer Pool & MVCC

Step inside PostgreSQL and InnoDB: sequential write-ahead logs, dirty-page buffer pools, snapshot MVCC, and vacuum bloat.

TREE HEIGHT
2 levels
LOOKUP HOPS
2 pages
PAGE SPLITS
3 splits
INDEXED KEYS
8 keys
Database Storage Engine & MVCC Internals Lab
Order-4 B+Tree (Max 3 Keys / Page · Click any leaf key to trace lookup)Height: 2 · Splits: 3 · Keys: 8
ROOT355582LEAF L11022LEAF L23548LEAF L45568LEAF L58291
Point Lookup key=48 → path R3 → L2 (2 page hops · HIT)
In This LessonStep 1 of 6
What You Will Master
  • ✓Understand how sequential WAL appends deliver ACID durability without slow random disk writes
  • ✓Size the RAM buffer pool to keep hot working sets in memory and avoid page-thrash eviction
  • ✓See how MVCC lets readers never block writers by serving versioned row snapshots
  • ✓Prevent dead-tuple table bloat and transaction ID wraparound with tuned autovacuum

Architectural Trade-Off Comparison Matrix

PatternBest ForKey Trade-Off
Write-Ahead Log (WAL)Fast durable commits via sequential `fsync` before modifying heap pagesRequires periodic checkpoints to bound crash-recovery replay time
Buffer Pool (LRU/Clock)Absorbing hot reads and coalescing multiple dirty page edits in RAMWhen working set exceeds RAM, page thrashing spikes IOPS 10×
MVCC Row VersionsHigh-concurrency OLTP where analytical reads coexist with live writesUpdates create dead tuples that must be reclaimed asynchronously
Autovacuum & HOT UpdatesKeeping B-Trees compact and preventing table bloat on update-heavy tablesLong idle-in-transaction sessions pin old snapshots and block vacuum

Step-by-Step Architectural Breakdown (6 Steps)

Full architectural walkthrough transcript and state transitions for WAL, Buffer Pool & MVCC.

STEP 01 · PROBLEMJump to step →

In-Place B+Tree Page Splits & Random Disk I/O

Updating scattered B+Tree pages directly on disk requires random page mutations and **page splits** whenever a leaf page overflows—and if power fails mid-split without a Write-Ahead Log, the tree corrupts into a half-updated state.

watch:Click "+ Trigger Page Split" or insert keys on the live Order-4 B+Tree stage to watch leaf pages split and promote keys upward.

Random I/OB+Tree Page Splitfsync LatencyCrash Corruption
STEP 02 · SOLUTIONJump to step →

Sequential WAL, RAM Memtable & SSTable Flushes

On `COMMIT`, modern storage engines append sequentially to the **Write-Ahead Log (WAL)**, mutate RAM (Buffer Pool or Memtable), and acknowledge immediately. Background flushes and compaction merge immutable files sequentially without blocking commits.

good:Click Write Key, Flush Memtable → L0, and Compact L0 → L1 on the stage to trace sequential WAL writes and Bloom-filtered lookups live.

Write-Ahead LogMemtable / Buffer PoolSSTable FlushBloom Filter
STEP 03 · TECHNIQUEJump to step →

MVCC: Readers Never Block Writers (Snapshot Isolation)

Under **Multi-Version Concurrency Control (MVCC)**, an `UPDATE` writes a new row version tagged with transaction ID (`xmin`) rather than overwriting in place. Concurrent readers see a consistent point-in-time snapshot without taking read locks.

idea:Switch between Read Committed and Snapshot (MVCC) on the timeline stage to watch how `xmin`/`xmax` visibility prevents Non-Repeatable Reads!

MVCCSnapshot Isolationxmin / xmaxUndo Log
STEP 04 · TRADE-OFFJump to step →

Write Skew, Phantom Reads & Dead Tuple Bloat

Even **Snapshot Isolation** cannot stop **Write Skew** (two transactions reading the same snapshot and updating disjoint rows that violate a cross-row invariant). Meanwhile, superseded MVCC row versions accumulate as **dead tuples** until **Autovacuum** reclaims them.

watch:Switch to Serializable (SSI) on the stage to see how predicate dependency tracking aborts Txn B before 0 doctors remain on-call.

Write SkewSerializable (SSI)Dead TuplesAutovacuum
STEP 05 · TRADE-OFFJump to step →

Compaction, Tombstones & Checkpoint Pacing

Whether pacing B+Tree dirty-page checkpoints or running **LSM-Tree Compaction**, background cleanup reclaims deleted **tombstones**, deduplicates stale row versions, and bounds both disk footprint and crash recovery replay time.

idea:Compare uncompacted overlapping L0 files against freshly compacted disjoint L1 tables right on the stage.

CompactionTombstone GCCheckpoint PacingWAL Replay
STEP 06 · RECAPJump to step →

OLTP Storage Engine & MVCC Recap

Modern databases combine **Sequential WAL** for crash durability, **B+Tree** or **LSM-Tree** indexes for fast reads/writes, and **MVCC Snapshots** (upgradable to Serializable SSI) so concurrent transactions stay fast and consistent.

good:Use the 3 mode tabs above (B+Tree Index · LSM-Tree & Bloom · MVCC Timeline) to test any storage engine trade-off hands-on.

ACID EngineB+Tree vs LSMMVCCSerializable SSI

Related Production Deep-Dives & Simulators

Related Systems Course
Free · Verifiable Credential

FS-401RAG Engineer

Build evidence-carrying retrieval systems from ingestion and provenance through search reranking grounded generation and evaluation.

21 concepts~25h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.