Skip to content
LESSON 11 / 50Intermediatewiredtiger

WiredTiger B-Tree Internal vs Leaf Page Layout

WiredTiger structures both data collections and indexes as B-Trees, organizing data into Internal branch pages and Leaf data pages.

Interactive Engine Simulator

WiredTiger Storage Engine: Cache, Journal & Checkpoints

Simulate RAM page states, dirty page eviction thresholds, WAL journaling, and 60-second checkpoint disk flushes.

Dirty Page Ratio
50%
Eviction triggers at 80%
Journal WAL LSN
#1048
Flushed every 100ms
Last Checkpoint
18s ago
Default period: 60s
Node State
HEALTHY
WiredTiger Engine
1. RAM Cache (Volatile)4 Pages
p-1users: [u1..u20]
CLEAN
p-2orders: [o101..o150]
DIRTY
p-3products: [p1..p50]
CLEAN
p-4users: [u21..u40]
DIRTY
2. Journal (WAL Ring Buffer)fsync 100ms
Active Journal File:WiredTigerLog.0000000001
Current LSN:#1048
Persistence guarantee:Write Concern j:true
Sequential append-only log enables instant crash recovery by replaying changes between last checkpoint and current LSN.
3. Disk Storage (.wt B-Trees)Checkpointed
Data Tables:collection-*.wt
Index Tables:index-*.wt
Root Pointer:WiredTiger.turtle
Disk files store B-Tree pages with Snappy / zlib compression. Only updated during checkpoint flush or heavy eviction.
ENGINE_LOG:Engine initialized. WiredTiger cache allocated (50% RAM minus 1GB).

1. Formal Definition & Architecture Intent

WiredTiger is MongoDB's default pluggable storage engine. It organizes data and indexes using B-Trees (or LSM trees for specialized workloads). Internal pages store navigation keys and child page pointers, while Leaf pages store actual key-value pairs (document payloads or index record IDs).

2. Explain Like I'm 5 (Mental Model)

Think of WiredTiger as a high-speed library filing system: the card catalog shelves (Internal pages) guide you to the specific drawer (Leaf page) containing the exact document folder.

3. Real-World Architecture Example

Navigating an index B-Tree on user email addresses.

Sample BSON Documents:
Collection: db.system.indexes
{
  "page_type": "leaf",
  "entries": [
    {
      "key": "alice@cloud.io",
      "record_id": 1042
    },
    {
      "key": "bob@cloud.io",
      "record_id": 1043
    }
  ]
}

Internal pages route lookups down through tree levels to the leaf page holding the record pointer in O(log N) time.

4. MQL Implementation Steps

Step 1: Inspect collection WiredTiger page statistics
db.users.stats().wiredTiger["block-manager"];
Inspects allocated block bytes and page reuse metrics.
Step 2: Check B-Tree page size configuration
db.users.stats().wiredTiger["creationString"];
Shows internal_page_max (default 4KB) and leaf_page_max (default 32KB).

5. Critical Engineering Rules

Rule / ConstraintUnderlying Reason & Impact
internal_page_max (4KB)Keeps internal navigation nodes small and high-fanout, maximizing cache fit.
leaf_page_max (32KB)Default maximum uncompressed size for leaf pages before triggering a page split.

6. Deep Dive: B-Tree Page Splitting in WiredTiger

When insertions or updates cause a leaf page to exceed leaf_page_max, WiredTiger reconciles the page in memory. It splits the page into two or more daughter pages, inserts a new separator key into the parent internal page, and queues the dirty pages for writing to disk at the next checkpoint.

// Stats tracking page splits:
db.serverStatus().wiredTiger.btree["pages split by reconciliation"];
Production Warning: Frequent random inserts into UUID indexes trigger constant mid-page splits, degrading I/O performance.

7. Architectural Trade-offs

Advantages
  • •High fanout reduces B-Tree height to 3-4 levels for millions of documents
  • •Configurable leaf and internal page boundaries optimize for read vs write heavy workloads
  • •Lock-free algorithms minimize mutex contention during tree traversals
Disadvantages & Gotchas
  • •Page splits require updating parent internal pages, temporarily creating dirty cache entries
  • •Random insertion workloads can leave leaf pages partially empty (fragmented)

8. Technical Interview Questions

Q1: Why does WiredTiger use different default page sizes for internal nodes (4KB) vs leaf nodes (32KB)?

Internal nodes only store separator keys and 64-bit child page pointers; keeping them at 4KB ensures high fanout and allows all internal routing pages to stay permanently pinned in RAM. Leaf nodes store full document or index payloads, where a larger 32KB size maximizes sequential disk I/O throughput and compression ratios.

9. Staff-Level Ready Answer

"WiredTiger structures collections and indexes as B-Trees. Internal pages default to 4KB for high fanout and fast routing, while leaf pages default to 32KB to balance compression efficiency and disk I/O. When leaf pages exceed the limit, WiredTiger performs in-memory reconciliation page splits."

10. Quick Knowledge Check

What is the default uncompressed maximum leaf page size in WiredTiger for standard collections?