WiredTiger Journaling & fsync Durability Mechanics
The WiredTiger write-ahead journal logs raw data mutations sequentially to non-volatile disk, guaranteeing ACID durability between 60-second checkpoint intervals.
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
The WiredTiger Journal is an append-only write-ahead log (WAL) stored in the journal/ directory. Because database checkpoints only occur every 60 seconds, all intermediate write operations are written sequentially to the journal on non-volatile disk. If mongod crashes, the journal is replayed to reconstruct all committed writes.
2. Explain Like I'm 5 (Mental Model)
Checkpoints are taking a full photograph of your room once an hour. The journal is writing down every item you move in a notepad as soon as you move it. If the power cuts, you look at the last photo and read your notes to put everything in its exact place.
3. Real-World Architecture Example
A financial payment write with { j: true } write concern guaranteeing on-disk persistence before confirming to the client.
{
"_id": "tx_9921",
"from": "u1",
"to": "u2",
"amount": 500
}With j: true, mongod forces an fsync on the journal buffer, guaranteeing durability before returning success.
4. MQL Implementation Steps
db.transfers.insertOne(
{ from: "u1", to: "u2", amount: 500 },
{ writeConcern: { w: "majority", j: true, wtimeout: 5000 } }
);5. Critical Engineering Rules
| Rule / Constraint | Underlying Reason & Impact |
|---|---|
| Default Commit Interval | WiredTiger flushes journal records to disk every 100 milliseconds (commitIntervalMs). |
| j: true vs j: false | j: true commits synchronously to disk (fsync); j: false confirms as soon as memory buffers are updated. |
6. Deep Dive: Group Commit & Batching in the Journal Ring Buffer
Invoking fsync for every individual client write would limit throughput to disk IOPS limits (a few thousand writes/sec). WiredTiger implements Group Commit: multiple concurrent client writes group their records into a shared in-memory journal buffer. A single thread executes fsync, satisfying dozens of waiting client write concerns in a single disk cycle.
// Journal statistics in serverStatus: db.serverStatus().wiredTiger.log; // "log bytes write": total bytes appended // "log sync operations": number of physical fsync calls to disk
7. Architectural Trade-offs
- •Guarantees ACID Durability without requiring full B-Tree page writes to disk on every insert
- •Sequential disk writes to the journal are orders of magnitude faster than random B-Tree page writes
- •Group commit amortizes disk fsync latency across concurrent client threads
- •Synchronous { j: true } writes add 2-10ms of disk I/O latency to client request cycles
- •Journaling consumes continuous disk write I/O bandwidth
8. Technical Interview Questions
With { j: false }, writes are acknowledged in memory. The journal buffer flushes to disk every 100ms (commitIntervalMs). Therefore, the maximum data loss window on an abrupt power loss is up to 100 milliseconds. With { j: true }, the data loss window is exactly 0.
9. Staff-Level Ready Answer
"WiredTiger uses write-ahead journaling to guarantee durability between 60-second checkpoints. Journal buffers are flushed sequentially to disk every 100ms by default, or immediately when writes request { j: true }. On crash recovery, WiredTiger loads the last checkpoint and replays journal logs to reconstruct committed state."
10. Quick Knowledge Check
What is the default maximum journal commit interval (commitIntervalMs) in WiredTiger for background syncs?