Sharding
Splitting one dataset across separate machines, and the queries that stop being possible once you do.
Sharding
What each access pattern costs
Splitting one dataset across separate machines, and the queries that stop being possible once you do.
What each access pattern costs
A shard is one part of a larger dataset stored on a separate node or cluster member. A sharding rule maps each record to a shard, commonly by range or hash of a shard key. An application or routing layer uses that key to locate the record.
A shard is one part of a larger dataset stored on a separate node or cluster member. A sharding rule maps each record to a shard, commonly by range or hash of a shard key. An application or routing layer uses that key to locate the record.
Sharding can add capacity when one server no longer meets storage or throughput needs. It also adds coordination, operations, and failure modes. Scaling a single database, archiving old data, or adding indexes may be simpler; measure the bottleneck before sharding.
A good shard key distributes writes and storage while appearing in common queries. A key with only a few values or one extremely popular value can create a hot shard. Queries that omit the key may need to contact many shards, and cross-shard transactions or joins can be more expensive.
Changing the shard key or adding nodes may require data movement and rebalancing. Design how routing metadata changes, how resharding is observed, and what happens when a shard is unavailable.
Partitioning divides a logical table into pieces managed within a database system. Sharding distributes data across separate nodes and therefore requires routing and coordination. Some products combine both ideas. See partitioning.
Sharding by tenant ID can keep each tenant's requests on one shard, making tenant-scoped reads and transactions local. But a few unusually large tenants can create hot shards, and an administrative query across all tenants must fan out. Hashing tenant IDs may balance count but not workload size. Range-based placement can make range scans easier but may concentrate new writes. Track per-shard storage, request rate, and latency, and plan for a tenant that outgrows one shard.
There is rarely one key that makes every access local. A tenant-scoped request may fit a tenant key, while a global time-range report can touch all shards. Record the fraction of requests that include the proposed key and estimate the fan-out for the rest. Also check whether a single tenant can exceed one shard's capacity. If both tenant isolation and global reporting matter, the architecture may need a separate analytical copy rather than forcing one shard key to serve incompatible workloads.
A shard map must support moving data when a node is added, removed, or overloaded. Define how routing changes without losing writes, how readers handle a moving range, and how progress is monitored. Consistent hashing or range splitting can help, but do not remove the need for a migration protocol and rollback plan. Backups and restores should be tested at both shard and whole-dataset levels. Operational complexity is part of the cost of sharding, even when the key distribution looks ideal on paper.
Answer without scrolling back up.
What is the difference between partitioning and sharding?
The machine boundary is the whole difficulty. Anything that needed a global view - joins, unique constraints, transactions - has to be rebuilt or given up.
What happens to a query that does not name the shard key?
Scatter-gather. This is why the shard key is a decision about which queries stay cheap forever, not a schema detail.
Why do virtual buckets make rebalancing easier?
With a plain hash(key) % N rule, adding a shard changes almost every row's destination. Consistent hashing solves the same problem by moving only one arc of the ring.
Shard a table by a key, route a query to the right partition, and see the four capabilities you lose when data lives on separate machines.