Skip to content

WAL: The Definitive Tutorial

Master Write-Ahead Logging — the single most important concept in database internals. From crash recovery basics to cutting-edge NVM research.

Seven chapters. Progressive difficulty. From “why do databases crash?” to “how does Aurora’s log-is-the-database architecture work?” — each chapter builds on the last.

Level: Beginner · Time: ~45 min

Why databases need WAL. The crash problem, ACID durability, the Steal/Force matrix, and the WAL protocol itself — the single invariant every database must maintain.

Page Topic
The Crash Problem Why partial writes break databases
ACID & Durability How WAL provides the D in ACID
Steal/Force Matrix Buffer management policy choices
The WAL Protocol The one rule that must never break

Level: Beginner–Intermediate · Time: ~60 min

Log records, LSNs, file formats, checkpoints, group commit, and concurrency. The mechanical details of how WAL works inside a database engine.

Page Topic
Log Records & LSN Record structure and sequence numbers
WAL File Formats On-disk layout across systems
Checkpoints Bounding recovery, enabling recycling
Group Commit Batching fsyncs for throughput
Concurrency WAL and multi-writer coordination

Level: Intermediate · Time: ~75 min

The ARIES algorithm — Analysis, Redo, Undo — with CLRs, the ATT/DPT, and a full worked example. The recovery algorithm behind PostgreSQL, DB2, and SQL Server.

Page Topic
Overview Three-pass recovery model
Analysis Pass Building ATT and DPT
Redo Pass Idempotent forward replay
Undo Pass & CLRs Rolling back active transactions
Worked Example Step-by-step crash recovery

Level: Intermediate · Time: ~60 min

How production databases implement WAL: SQLite, PostgreSQL, InnoDB, and LSM-tree engines. Compare architectures side by side.

Page Topic
SQLite WAL Frame-based WAL, checkpoint modes
PostgreSQL WAL Segments, XLogRecords, PITR
InnoDB Redo/Undo Mini-transactions, doublewrite
LSM Engines RocksDB/Pebble WAL for memtables

Level: Advanced · Time: ~60 min

Consensus logs, distributed database architectures, change data capture, and event sourcing. When the log spans machines.

Page Topic
Raft Consensus Log Distributed WAL via quorum replication
Distributed Databases CockroachDB, TiKV, Aurora, OceanBase
CDC from WAL Logical decoding, Debezium, outbox
Event Sourcing Domain events as a WAL pattern

Level: Expert · Time: ~75 min

Performance tuning, modern hardware (NVMe, PMEM, io_uring), corruption debugging, and production anti-patterns. For DBAs and engine developers.

Page Topic
Performance Tuning pg_stat views, config matrix, benchmarks
Modern Hardware NVMe, PMEM, WBL, io_uring
Debugging Corruption pg_waldump, PITR, WAL-Reset bug
Pitfalls & Anti-Patterns Stale slots, fsync=off, untested backups

Level: All · Time: As needed

Quick-reference materials: cheat sheet, interview questions, paper reading list, and complete glossary.

Page Topic
Cheat Sheet One-page WAL reference
Interview Questions 40 questions, fundamentals to expert
Papers & Reading List Essential WAL research
Glossary ~60 terms defined

Chapters 1–2 assume no prior WAL knowledge. Chapter 3 (ARIES) is the inflection point — if you understand three-pass recovery, everything after clicks into place. Chapters 5–6 are for engineers who operate or build database systems.

Every content page ends with a Quick Quiz — expandable <details> sections with questions and answers. Use them to verify understanding before moving to the next chapter. If you can’t answer a quiz question, re-read that section.

Several pages include interactive React components:

  • Crash Recovery Demo (Chapter 1) — watch WAL protect against partial writes
  • Replication Flow Demo (Chapter 5) — trace WAL records through replication and CDC

Look for the 💡 Memory Hook asides throughout — analogies designed to make concepts stick. “WAL is a film reel.” “Checkpoint is a save point.” “CDC is WAL’s public API.”

Audience Chapters Time
Curious developer 1–2 ~2 hours
Backend engineer 1–4 ~4 hours
Database engineer 1–6 ~6 hours
Complete mastery 1–7 + papers ~10 hours