Skip to content
LESSON 13 / 50Advancedwiredtiger

WiredTiger Checkpoints & Crash Consistency

WiredTiger periodically writes consistent filesystem snapshots (checkpoints) to disk every 60 seconds, acting as recovery anchors during crash reboots.

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

A Checkpoint in WiredTiger is a persistent, crash-consistent snapshot of the entire database written to disk. By default, MongoDB triggers a checkpoint every 60 seconds or after 2GB of journal data. If the server crashes or loses power, WiredTiger recovers by loading the latest checkpoint and replaying the journal from that point forward.

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

Checkpoints are like autosaves in a video game every 60 seconds. If your console loses power, the game reloads from the last autosave and uses your quick-log (journal) to catch up on the last few seconds.

3. Real-World Architecture Example

Observing checkpoint creation during high-volume data ingestion.

Sample BSON Documents:
Collection: db.serverStatus.wiredTiger.checkpoint
{
  "checkpoint count": 450,
  "last checkpoint duration (msecs)": 320,
  "bytes written": 419430400
}

Every 60 seconds, all dirty B-Tree pages are written to persistent blocks on disk and the root pointers are atomically updated.

4. MQL Implementation Steps

Step 1: Trigger a manual checkpoint in mongosh
db.fsyncLock(); // Flushes all dirty pages and creates checkpoint
db.fsyncUnlock(); // Resumes writes
Useful before taking consistent filesystem-level LVM/EBS snapshots.
Step 2: Check last checkpoint runtime stats
db.serverStatus().wiredTiger.transaction["transaction checkpoint total time (msecs)"];
Measures I/O latency spent syncing dirty pages to disk.

5. Critical Engineering Rules

Rule / ConstraintUnderlying Reason & Impact
FrequencyExecutes every 60 seconds or when 2GB of journal data has been written.
Non-Blocking WritesCheckpoints run concurrently with ongoing reads and writes using copy-on-write page reconciliation.

6. Deep Dive: Copy-On-Write and Atomic Root Pointer Swap

WiredTiger does not overwrite existing disk blocks in place during a checkpoint. Instead, it writes dirty pages into newly allocated free disk blocks (Copy-On-Write). Once all pages are safely written and fsynced, WiredTiger atomically updates the root block pointers in the metadata file (WiredTiger.wt). If a crash happens midway, the previous checkpoint remains 100% uncorrupted.

// View checkpoint historical runtimes:
db.serverStatus().wiredTiger.transaction["transaction checkpoint most recent time (msecs)"];
Production Warning: High disk latency during checkpoints can cause periodic write stalls every 60 seconds.

7. Architectural Trade-offs

Advantages
  • •Guarantees full database crash recovery even if the server suffers an abrupt power outage
  • •Copy-on-write design prevents database file corruption during in-flight crashes
  • •Enables non-disruptive, crash-consistent storage block backups (EBS/SAN snapshots)
Disadvantages & Gotchas
  • •Causes periodic I/O write spikes every 60 seconds as accumulated dirty pages are flushed
  • •Free block fragmentation requires background space reclamation

8. Technical Interview Questions

Q1: How do WiredTiger checkpoints and the write-ahead journal work together to guarantee Durability?

Checkpoints create a complete, consistent snapshot of all collection and index data on disk every 60 seconds. The write-ahead journal records operations between checkpoints. Upon recovery after an unexpected crash, WiredTiger loads the last successful checkpoint and replays all journal records committed since that checkpoint, restoring 100% of committed transactions.

9. Staff-Level Ready Answer

"Checkpoints occur every 60 seconds (or 2GB of journal), flushing all dirty cache pages to disk using a copy-on-write strategy. Recovery involves rolling back to the last valid checkpoint and replaying the journal from that point forward."

10. Quick Knowledge Check

What is the default time interval between automated WiredTiger checkpoints in MongoDB?