MongoDB
maang.io System Design Series
MongoDB stores flexible documents (BSON) instead of rows, letting you embed related data and evolve schemas freely. Under the hood: the WiredTiger engine (B-tree + document-level MVCC), replica sets with an oplog and elections, sharding for horizontal scale, and tunable read/write concerns. It's the default document store you'll compare against relational and wide-column options.
This deep dive comes in four parts:
- Foundations & Core Concepts — the document model and embedding vs referencing.
- Internals — WiredTiger, replica sets/oplog/elections, and sharding, with worked numbers.
- Advanced Internals — indexes, the aggregation pipeline, and read/write concerns.
- Interview — Staff/Principal Q&A: shard-key choice, consistency, and document-vs-relational.
MongoDB — Part 2: Internals & The Write Path
maang.io System Design Series
What is this?
Back to the records office. Part 1 stayed at the counter — folders, drawers, what goes in a folder. Now we go into the back room where the folders physically live, and watch exactly what a clerk does when someone hands over a change.
A careless clerk would walk straight to the shelf, pull the folder, edit it in place, and reshelve it — slow, and if the building loses power mid-edit you have a half-written folder and no idea what was in flight. MongoDB's clerk is disciplined. First it scribbles the change into an intake logbook by the door (so nothing acknowledged is ever lost, even to a power cut). Then it applies the change to a working copy kept on a nearby desk (fast RAM, no shelf trip). Only periodically does it walk the whole desk's worth of changes back to the permanent shelves in one organized trip.
That back room is the WiredTiger storage engine — MongoDB's default engine since version 3.2 — and understanding it explains every durability and performance promise from Part 1.
The one-line idea: WiredTiger keeps your working set in an in-memory cache, makes writes durable immediately via a journal (a write-ahead log), and only flushes a consistent snapshot to the data files at a checkpoint every ~60 seconds. RAM speed for the hot path, the journal for durability, checkpoints for a clean on-disk baseline — that's the whole trick.
Let's follow a write down into it.
Sign in to continue reading
The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.
Sign in to read the full lesson