MMAPv1 vs WiredTiger: The Storage Architecture Evolution
Analyze the architectural leap from MongoDB's legacy MMAPv1 engine (database-level locking, uncompressed) to WiredTiger (document-level concurrency, compression).
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
MMAPv1 was MongoDB's original storage engine, relying directly on the operating system's memory-mapped files (mmap system call) for memory management. In MongoDB 3.0, WiredTiger was introduced and became default in 3.2, replacing MMAPv1 with document-level concurrency, block compression, and true B-Tree cache reconciliation.
2. Explain Like I'm 5 (Mental Model)
MMAPv1 was like letting the city council (the OS) manage your store's inventory: whenever someone bought an apple, the council locked the whole grocery store. WiredTiger is having your own professional in-house manager with specialized shelves and individual customer carts.
3. Real-World Architecture Example
Contrasting concurrency between MMAPv1 and WiredTiger.
{
"mmapv1": {
"concurrency": "Database / Collection Level Locking",
"compression": "None (Raw Disk Blocks)"
},
"wiredTiger": {
"concurrency": "Document Level Lock-Free Concurrency",
"compression": "Snappy / zstd (up to 80% savings)"
}
}WiredTiger delivered a 7-10x throughput increase on concurrent write workloads over MMAPv1.
4. MQL Implementation Steps
db.serverStatus().storageEngine;
// Returns { name: "wiredTiger", supportsCommittedReads: true, ... }5. Critical Engineering Rules
| Rule / Constraint | Underlying Reason & Impact |
|---|---|
| Locking Granularity | MMAPv1 used database/collection locking; WiredTiger uses document-level optimistic concurrency. |
| Compression | MMAPv1 had zero compression; WiredTiger compresses collections and index prefixes. |
| Memory Management | MMAPv1 delegated memory to the OS kernel; WiredTiger manages its own dedicated cache. |
6. Deep Dive: Why Delegating Memory to the OS Failed at Scale
MMAPv1 simply called mmap() on data files and allowed the OS kernel's page replacement algorithm to decide what to evict. However, the OS kernel has zero semantic awareness of B-Tree structure or transaction dependencies. The OS frequently evicted hot root B-Tree index pages while keeping cold document pages, leading to catastrophic disk thrashing.
// WiredTiger engine configuration in modern mongod: storage: engine: wiredTiger
7. Architectural Trade-offs
- •Document-level concurrency allows thousands of concurrent writes to the same collection
- •Built-in block compression cuts storage footprint by up to 80%
- •Dedicated memory cache management prioritizes B-Tree index structures over cold raw data
- •Requires explicit cache configuration to avoid memory contention with external applications
- •Increased CPU utilization compared to raw zero-overhead OS memory mapping
8. Technical Interview Questions
1. Coarse-grained locking: MMAPv1 locked the entire database or collection on writes, bottlenecking concurrent write workloads. WiredTiger introduced document-level concurrency. 2. Zero compression: MMAPv1 stored raw uncompressed BSON on disk. WiredTiger introduced Snappy/zstd block compression, slashing disk footprint by 60-80%.
9. Staff-Level Ready Answer
"MMAPv1 relied on OS memory mapping and suffered from collection-level locking and zero compression. WiredTiger introduced document-level concurrency, dedicated buffer cache management, and Snappy/zstd compression, yielding 7-10x higher write throughput and 70% storage reduction."
10. Quick Knowledge Check
In which major version of MongoDB was the legacy MMAPv1 storage engine completely removed?