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.
WiredTiger Storage Engine: Cache, Journal & Checkpoints
Simulate RAM page states, dirty page eviction thresholds, WAL journaling, and 60-second checkpoint disk flushes.
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.
{
"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
db.users.stats().wiredTiger["block-manager"];
db.users.stats().wiredTiger["creationString"];
5. Critical Engineering Rules
| Rule / Constraint | Underlying 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"];
7. Architectural Trade-offs
- •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
- •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
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?