WiredTiger MVCC & In-Memory Snapshot Isolation
WiredTiger implements multi-version concurrency control (MVCC) in memory using linked update chains, allowing readers to query consistent snapshots without blocking writers.
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
Multi-Version Concurrency Control (MVCC) in WiredTiger ensures that readers do not block writers, and writers do not block readers. When a document is modified, WiredTiger does not overwrite the existing record in memory. Instead, it prepends a new update structure containing the new data and transaction commit timestamp to an in-memory update chain linked to the B-Tree row.
2. Explain Like I'm 5 (Mental Model)
When an author edits a shared document, instead of erasing sentences and locking the page, they stick a transparent sticky note over the paragraph. Readers who arrived earlier read the original page; new readers read the sticky note.
3. Real-World Architecture Example
Concurrent read queries reading customer balance while an update transaction is in flight.
{
"_id": "acc_01",
"balance": 500
}A reader with snapshot timestamp 102 reads 500, while a reader with timestamp 106 reads 400 concurrently without any mutex locks.
4. MQL Implementation Steps
const session = db.getMongo().startSession();
session.startTransaction({ readConcern: { level: "snapshot" } });
const acc = session.getDatabase("bank").accounts.findOne({ _id: "acc_01" });
session.commitTransaction();5. Critical Engineering Rules
| Rule / Constraint | Underlying Reason & Impact |
|---|---|
| Readers vs Writers | Readers read historical versions from update chains without acquiring write locks. |
| Update Chains | Each memory row tuple maintains a linked list of update structures ordered by timestamp. |
6. Deep Dive: Update Chain Traversal & Reconciliation
When a reader traverses a B-Tree page, it evaluates the update chain on each row against its active transaction read timestamp. If the top version is uncommitted or committed after the reader's snapshot timestamp, WiredTiger walks backward along the pointer chain until it finds the version committed before its snapshot.
// Structure of in-memory row: // [Row Key: "acc_01"] -> [Update Tx: 108, Balance: 400] -> [Update Tx: 100, Balance: 500]
7. Architectural Trade-offs
- •Eliminates read-write lock contention across concurrent clients
- •Provides true point-in-time Snapshot Isolation for multi-document ACID transactions
- •Historical versions are garbage collected automatically during in-memory page reconciliation
- •Update chains consume working cache RAM until reconciled and evicted
- •High write contention on a single document creates long update chains that slow reads
8. Technical Interview Questions
WiredTiger uses optimistic concurrency control for row updates. If two concurrent transactions attempt to update the same document, the second transaction detects a write conflict (WriteConflictException) and automatically retries internally, or aborts if operating within an explicit client transaction.
9. Staff-Level Ready Answer
"WiredTiger implements MVCC using in-memory update chains attached to B-Tree leaf tuples. Readers consult their snapshot timestamp and traverse the chain to view consistent point-in-time data without acquiring locks. When pages are reconciled during checkpoints or eviction, committed updates are collapsed into base leaf blocks."
10. Quick Knowledge Check
Under WiredTiger MVCC, what structure is attached to a B-Tree row in memory to record concurrent modifications?