Skip to content
LESSON 20 / 50Advancedwiredtiger

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).

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

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.

Sample BSON Documents:
Collection: db.engine_comparison
{
  "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

Step 1: Verify active storage engine in mongod
db.serverStatus().storageEngine;
// Returns { name: "wiredTiger", supportsCommittedReads: true, ... }
MMAPv1 was completely deprecated and removed in MongoDB 4.2.

5. Critical Engineering Rules

Rule / ConstraintUnderlying Reason & Impact
Locking GranularityMMAPv1 used database/collection locking; WiredTiger uses document-level optimistic concurrency.
CompressionMMAPv1 had zero compression; WiredTiger compresses collections and index prefixes.
Memory ManagementMMAPv1 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
Production Warning: Legacy MMAPv1 storage files cannot be directly booted by MongoDB 4.2+ binaries.

7. Architectural Trade-offs

Advantages
  • •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
Disadvantages & Gotchas
  • •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

Q1: What were the two biggest architectural limitations of the legacy MMAPv1 engine that WiredTiger solved?

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?