System Design Space
Knowledge graphSettings

Updated: May 4, 2026 at 7:57 AM

MongoDB: document model, replication, and consistency

medium

MongoDB document modeling, replica sets, sharding, read and write concerns, multi-document transactions, and practical consistency guarantees.

MongoDB is interesting not because flexible schema sounds attractive on its own, but because the document model reshapes the balance between delivery speed, atomic operations, and the cost of consistency.

In day-to-day work, this chapter helps you reason through document shape, aggregates, read concern, and write concern before fast product decisions turn into scale and query-complexity problems.

In interviews and design reviews, it helps explain why the document model genuinely speeds up change in this domain and which limits the team accepts deliberately rather than by accident.

Practical value of this chapter

Document boundaries

Model aggregates and document shape so frequent operations stay atomic without expensive joins.

Consistency controls

Tune read/write concern per user flow instead of applying one global consistency setting.

Shard-key discipline

Choose shard key using load distribution, hot partition risk, and rebalancing cost.

Interview framing

Show why document model improves delivery speed and which limitations you accept deliberately.

Source

MongoDB

MongoDB history, document modeling, replication, sharding, transactions, and practical consistency guarantees.

Перейти на сайт

MongoDB started as a flexible NoSQL database for JSON-like documents and grew into a platform with replica sets, sharding, and multi-document transactions. This chapter explains where the document model helps, which guarantees can be configured, and why MongoDB defaults changed after real-world consistency analysis.

History: key milestones

2007

Start of development

10gen starts building MongoDB as part of a broader PaaS platform.

2009

Release and open source

The company shifts focus from the platform to MongoDB as an open-source database with commercial support.

2013

MongoDB Inc.

10gen is renamed MongoDB Inc.

2016

Atlas

MongoDB Atlas appears as the managed DBaaS offering and gradually becomes the main way many teams consume the product.

2017

IPO

MongoDB goes public (ticker MDB).

2018

4.0: transactions and snapshots

Multi-document ACID transactions and consistent snapshot reads become available.

2021

5.0: w:majority by default

According to Wikipedia, the default write concern is raised to w:majority.

Documentation

Sharded Cluster Components

mongos, config servers, and shard replica sets as the basic cluster building blocks.

Перейти на сайт

MongoDB architecture (modern versions)

MongoDB has a client and driver layer, a routing and query layer, and a replication and sharding layer on top of the storage engine.

Clients and drivers
DriversBSONAuth/TLSConnection pool
Layer transition
Query router and execution
mongosParserPlannerExecutor
Layer transition
Replication and sharding
Replica setPrimary/SecondaryOplogConfig servers
Layer transition
Storage engine
WiredTigerJournalCacheIndexes
Layer transition
OS + hardware
FilesystemDiskCPU/RAMNetwork

Sharded cluster components

mongos (router)

Routes requests to target shards based on cluster metadata.

Config servers

Store cluster metadata and sharding state.

Shards (replica sets)

Each shard is deployed as a replica set.

Typical deployment modes

Standalone

Single mongod without sharding or replication.

Replica set

Primary + multiple secondaries, synchronized through oplog.

Sharded cluster

mongos + config servers + multiple shard replica sets.

DDL vs DML: how a request flows

DDL changes collection and index structure; DML works with documents. The visualizer below compares the execution chain for both request types.

How a request flows through MongoDB

Comparing the execution chain for DDL (schema) and DML (data)

Interactive replayStep 1/5

Active step

1. Client command

A CRUD request arrives through the driver.

Data operations

  • DML works with documents and indexes without changing schema.
  • Core pressure is on cache, indexing, and journaling.
  • Read/Write concern define the latency-vs-reliability tradeoff.
CRUD operationsOplogSharding-aware routing

Related chapter

Jepsen and consistency models

How Jepsen tests distributed systems and what consistency models mean.

Читать обзор

Consistency in MongoDB: what you can configure

In a distributed database, “consistency” is not one switch. It is a set of settings and trade-offs. Wikipedia highlights read concern, write concern, and transactions as key mechanisms.

Replication and sharding

MongoDB distributes data through replica sets and shards, so read and write paths must account for the network, failures, and replication lag.

Read and write guarantees

Read concern controls data freshness, while write concern defines how many replicas must acknowledge a write.

Multi-document transactions

Since version 4.0, MongoDB supports ACID transactions for operations that touch multiple documents.

How models and guarantees changed over time

Safer defaults

  • Wikipedia notes that the default write concern was increased to majority (w:majority), reducing the risk of losing acknowledged writes during failures.
  • For strict scenarios, it is important to consciously choose read/write concern levels and understand their impact on latency and availability.

What MongoDB guarantees today

  • Supports replication and sharding, as well as multi-document ACID transactions (since 4.0).
  • Read concern and write concern let teams balance speed, freshness, and data safety.
  • Wikipedia notes that in 5.0 the default write concern was raised to majority (w:majority).

Practical lesson for system design: when choosing MongoDB, agree upfront on the guarantees the product needs, then verify that configuration, drivers, and query paths actually set the expected read and write levels.

Related chapters

Enable tracking in Settings