WiredTiger Checkpoints & Crash Consistency
WiredTiger periodically writes consistent filesystem snapshots (checkpoints) to disk every 60 seconds, acting as recovery anchors during crash reboots.
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
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.
{
"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
db.fsyncLock(); // Flushes all dirty pages and creates checkpoint db.fsyncUnlock(); // Resumes writes
db.serverStatus().wiredTiger.transaction["transaction checkpoint total time (msecs)"];
5. Critical Engineering Rules
| Rule / Constraint | Underlying Reason & Impact |
|---|---|
| Frequency | Executes every 60 seconds or when 2GB of journal data has been written. |
| Non-Blocking Writes | Checkpoints 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)"];
7. Architectural Trade-offs
- •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)
- •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
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?