Skip to content
LESSON 16 / 50Advancedwiredtiger

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.

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

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.

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

Step 1: Execute write with explicit journal durability concern
db.transfers.insertOne(
  { from: "u1", to: "u2", amount: 500 },
  { writeConcern: { w: "majority", j: true, wtimeout: 5000 } }
);
j: true blocks client return until the journal entry is physically flushed to disk.

5. Critical Engineering Rules

Rule / ConstraintUnderlying Reason & Impact
Default Commit IntervalWiredTiger flushes journal records to disk every 100 milliseconds (commitIntervalMs).
j: true vs j: falsej: 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
Production Warning: Disabling journaling in standalone instances means an unexpected power outage can cause up to 60 seconds of data loss.

7. Architectural Trade-offs

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

Q1: If a MongoDB server experiences an abrupt power loss, what is the maximum window of data loss if writes were issued with { j: false } on a standalone instance?

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?