</> MAANG.io
system design · 201

Intermediate

Master system design interviews with scalable architecture patterns, distributed systems, and real-world design challenges.

0/124 solved 0% complete

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 3: Internals Advanced — Replication, Sharding & Consistency

maang.io System Design Series


What is this?

One records office is a single point of failure — burn the building down and the folders are gone; get too many patients and one clerk can't keep up. Real institutions solve both problems structurally. They keep branch offices with photocopies of every folder, kept in sync from a head office. And when one building can't physically hold all the folders, they split the archive across several buildings by some rule (say, surname), with a receptionist who knows which building holds which folders.

Those are MongoDB's two scaling axes, and they're independent:

  • Replication (replica sets) → availability & durability. Copies of the same data on multiple nodes; survive node loss.
  • Shardinghorizontal scale. Different slices of the data on different nodes; grow past one machine.

The one-line idea: a replica set keeps N copies of the data with one primary taking writes and secondaries tailing an oplog to stay in sync; sharding spreads the collection across many replica sets by a shard key, with a router (mongos) and a metadata directory (config servers) sending each query to the right shard. Consistency is a dial you set per operation with write/read concerns and read preferences.

This is the chapter where MongoDB becomes a distributed system. Let's build it up.


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

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.