Lesson 21 / 22

Sharding

Horizontally partition data across multiple servers.

Splitting data by shard key

Sharding distributes a collection's documents across multiple servers (shards) based on a chosen shard key, instead of one server holding it all.

When you need it

Reach for sharding when data size or write/read throughput outgrows what a single replica set can handle.

Quick check: What problem does sharding primarily solve?

  • Automatic failover when the primary goes down
  • Scaling storage and throughput beyond a single server
  • Validating document structure
Answer

Scaling storage and throughput beyond a single server — Sharding horizontally scales out data and load; failover is handled by replica sets instead.