Course contentsShow
← System Design
Lesson 229 of 1,9197. Database Scaling: ShardingFree lesson

What is Sharding?

Partitioning data across multiple database servers to distribute load and exceed single-server capacity limits.

What is Sharding?

You'll learn: How sharding splits your database horizontally across multiple servers to handle massive scale beyond what any single machine can support.

The Core Idea

Sharding (also called horizontal partitioning) means dividing your database into smaller, independent pieces called shards, with each shard living on a separate server. Instead of storing all your data on one massive database server, you split it across many servers based on some logical rule.

Think of it like a library system across multiple buildings. Instead of one giant library holding every book (which would be slow and eventually run out of space), you distribute books across multiple locations—maybe Building A handles authors A-M, and Building B handles N-Z. Each building operates independently but together they serve the complete collection.

Why Shard?

Up until now, you've learned about vertical scaling (bigger machines) and replication (read replicas). But even with replicas, all your write traffic still hits one primary server, and that primary must store all your data. Eventually you hit limits:

  • Storage capacity: One server can only hold so much data
  • Write throughput: One primary can only handle so many writes/second
  • Query performance: Even indexed queries slow down as tables grow massive

Sharding breaks these limits by spreading data across multiple independent databases that can all accept writes.

How It Works (Simplified)

You choose a shard key (like user_id), then use it to determine which shard stores each row. User 12345's data goes to Shard A, User 67890's goes to Shard B, etc.

Key Takeaway: Sharding partitions data horizontally across multiple database servers, allowing you to exceed single-server capacity and throughput limits by distributing both storage and write load.