Skip to main content
← CONCEPTS / DATABASES-STORAGE
An end-to-end domain learning journey

Copy-on-Write (CoW) B+Trees &
LMDB Memory-Mapped Snapshots.

In-place B+Trees require per-page latches and heavy WAL undo/redo logs; Copy-on-Write B+Trees (LMDB) write immutable shadow pages and atomically swap the root pointer for lock-free mmap reads.
Start the journey2 sections· Last modified Dec 1, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When using CoW B+Trees, keep read transactions short so old shadow pages can be reclaimed.

TL;DR30-second simplified summary
▾

Delivers zero-copy mmap reads at RAM speed with O(log_B N) path-copying writes.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
B+Tree page structure
POSIX mmap() & OS page cache
MVCC snapshot isolation
Full walkthrough · 2 stages
01
Stage 1 • Mechanicsintermediate

Shadow Path Cloning & Atomic Root Swap.

Why this matters: Explain how path-copying eliminates page latches and torn-page corruption.

Modifying 1 leaf in a 4-level B+Tree clones 4 pages into free space, leaving the previous root's entire tree intact for active readers.

02
Stage 2 • Trade-Offsadvanced

Long-Lived Reader Page Bloat & Write Amplification.

Why this matters: Highlight the operational boundary conditions of CoW B+Trees.

If a read transaction stays open for hours, freed shadow pages pinned by that old root cannot be reclaimed until the reader closes, causing file growth.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why do readers in LMDB require zero page latches?

Recommended Learning Flow