Horizontal scaling increases database capacity by spreading data and workload across additional servers. It contrasts with vertical scaling, which adds CPU, RAM, or storage to one server. Scaling out can be more cost-effective as data grows, but a larger network of servers adds management complexity. section 9.3
MongoDB scales out through sharding: a sharded collection is partitioned across shards, each holding part of its data. MongoDB balances data and distributes load as machines are added. Its self-contained documents help because retrieving one document need not require joins across servers. section 1.2 section 9.3
Figure 1.1 MongoDB’s sharding architecture enables horizontal scaling by distributing data across multiple servers. (Image © MongoDB 2024 CC BY-NC-SA 3.0)
The cluster diagram shows the application reaching shards through mongos query routers, rather than choosing a server for each query itself. section 1.2
Keep these operational distinctions in mind:
- Replication copies data to secondary members for availability and read distribution; writes still pass through the primary. Sharding partitions data, allowing writes to different shards to reach their respective primaries. Replication within each shard helps keep its data accessible after a server failure. section 9.0
- Sharding is chosen per collection. Unsharded collections remain on a database’s primary shard; MongoDB 8.0+ provides moveCollection to move them to another shard. section 9.3
- Atlas offers sharding as an option, but its cluster autoscaling does not add shards or convert a replica set into a sharded cluster. Do not mistake automatic tier or storage changes for horizontal scaling. section 9.0 section 10.2.3
When one server becomes the limit
If growing data exceeds a server’s RAM or strains disk I/O, upgrading that server may help only until its available configurations run out. Sharding offers another path: add servers and distribute the collection’s data and workload, while planning for the added operational complexity. section 9.3












