core practice · implementation task

Build a write-ahead log

Implement an append-only WAL: append + fsync each change before acknowledging it, and replay the log on startup to recover state.

The mechanism

The WAL is the database's promise: write the change to an append-only log and fsync it before touching the real data structure. A crash mid-write is recoverable by replaying the log. Durability before convenience.

Study Write-Ahead Log

Expected evidence

State survives a simulated crash by replaying the log.

Try this drill in the practice workspace →

Hints when you need them
  • fsync before you acknowledge the write.
  • Checkpoint so the log does not grow forever.

Watch for these mistakes

  • Acknowledging a write before the WAL is fsync'd
  • Letting the WAL grow forever with no checkpoint/truncation
  • Assuming a write() syscall means data is on disk

Check the sources

Browse all practice briefs