Database Sharding
A database scaling technique that distributes data across multiple database instances based on a partition key.
Definition
Sharding horizontally partitions database tables across multiple servers. Each shard holds a subset of data—perhaps users A-M on one shard and N-Z on another. This distributes both storage and query load.
Shard keys determine data distribution. User ID sharding keeps each user's data together. Geographic sharding groups data by region. The right key minimizes cross-shard queries while balancing load.
Why It Matters
Sharding enables databases to scale beyond single-server limits. When tables grow to billions of rows, no amount of hardware optimization helps—distribution across shards becomes necessary.
Sharding adds significant complexity. Transactions across shards, query routing, and shard rebalancing all require careful engineering. It's a last resort after exhausting simpler scaling options.
Examples in Practice
Instagram shards their massive tables by user ID. When you access your photos, queries go to your specific shard rather than scanning billions of photos across all users.
A growing startup delays sharding by optimizing queries and adding read replicas. Only after reaching 100M rows with continued growth do they invest in sharding infrastructure.