SkillByAIOpen interactive version →

Lesson 21 / 23

Sharding

Scale horizontally by sharding collections across servers using a well-chosen shard key.

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
  • Validating document structure
  • Formatting JSON output
  • Scaling storage and throughput beyond a single server
Answer

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