Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Eliminating B+Tree Page Latch Contention & WAL
Replay Lag via CoW Shadow Pages.

An embedded metadata index suffers 64-core reader latch contention and 45-second WAL recovery pauses after crashes; redesign it using Copy-on-Write shadow pages and dual meta-page pointers.
Start the journey2 stages· Last modified Dec 1, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When building a CoW B+Tree, fsync shadow pages before alternating meta0/meta1 root pointers.

TL;DR30-second simplified summary
▾

Removes 64-core root latch contention and 45s WAL replay pauses.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
B+Tree page latches
Copy-on-Write shadow paging
Dual meta-page atomic commit
Full walkthrough · 2 stages
01
Stage 1 • Bottleneckintermediate

Why In-Place Latches & WAL Undo Hurt Read-Heavy Indexes.

Why this matters: Quantify latch cache-line bouncing and crash recovery lag.

On a 64-core server, 1M reads/sec incrementing and decrementing a root page's shared latch causes severe CPU cache-line bouncing.

02
Stage 2 • Solutionadvanced

Dual Meta-Page Atomic Root Flip.

Why this matters: Guarantee atomic root updates without torn meta-pages.

Write the new root to meta[tx_id % 2] with a CRC32 checksum. Even if power fails mid-write to meta1, meta0 remains 100% valid.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does a CoW B+Tree alternate between two meta-pages (meta0 and meta1)?

Recommended Learning Flow