What Is Database Sharding?
Sharding splits a single logical database's data across multiple physical databases (shards), each holding a subset of the data, to scale beyond what one dat...
Published November 20, 2026
Sharding splits one large database into smaller pieces (shards) spread across servers, each holding a subset of the rows, so data and traffic scale beyond a single machine.
The concept
A shard key (user_id, region) decides which shard stores a row, typically by hashing or ranges. Queries with the key go to one shard; others must fan out.
Sharding adds complexity: cross-shard joins and transactions are hard, rebalancing is painful and a bad shard key creates hot spots.
Route by key
Practical examples
Hash routing
const shards = [db0, db1, db2]
const shardFor = (userId) => shards[userId % shards.length]
await shardFor(42).query('SELECT * FROM orders WHERE user_id = ?', [42])Range sharding
Shard A: users 1–1M · Shard B: 1M–2MBefore sharding try
Indexes, caching, read replicas, bigger hardware, partitioningCommon mistakes
- Sharding too early.
- A shard key that concentrates load (hot shard).
- Needing cross-shard joins everywhere.
Key takeaways
- Horizontal split of data.
- Shard key is crucial.
- Last resort after simpler scaling.
FAQ
Sharding vs partitioning?
Partitioning splits a table inside one database; sharding spreads across servers.
Replication vs sharding?
Replication copies the same data; sharding divides different data.