Sharding and Partitioning in System Design
Divide data when one storage path is not enough
Split ownership is different from replication
Copies for recovery would be replicas of a shard’s subset.
An application’s records may become too large or too busy for one storage setup. Partitioning divides a data set into parts. Sharding usually refers to distributing those parts across separate database nodes or groups.
Splitting data is different from copying it. A shard owns a subset of records; a replica holds a copy for availability or reads. A production system may use both, and the terms and guarantees vary by product.
What you’ll learn
- Distinguish a partition, a shard and a replica.
- Compare range and hash placement and observe a hot shard.
- Choose keys using real access patterns and account for rebalancing and cross-shard work.
The key determines where work goes
A partition or shard key is the value used to decide placement. Range placement keeps related key ranges together, which can help range queries. A steadily increasing timestamp can also concentrate new writes into the newest range.
Hash placement transforms a key to spread different values across buckets. This can distribute many distinct keys while making range queries less local. It does not split repeated requests for one exact key across every shard automatically.
Choose the key from both reads and writes. A query with the key can often target the owning part; a query without it may need several parts and combine their answers. The best distribution is not useful if normal requests become expensive fan-out queries.
Place records, then send one key a burst
Records and request load are different distributions
Range placement: keys 1–4 belong to A, 5–8 to B. Choose a key and route some work.
Changing strategy remaps this tiny in-memory example and resets counts. It is not a live migration implementation.
The eight sample keys are 1 through 8. Range mode assigns 1–4 to A and 5–8 to B. Hash mode uses odd keys for A and even keys for B: a simplified modulo example, not a real product hash.
Select a key and send six requests for it. Both modes still send those requests to one owner. Try several different keys and compare the per-shard request counts. These counts show placement and skew, not measured server throughput.
A balanced record count can hide an overloaded shard
A hot shard receives a disproportionate share of work. Four records on each shard do not guarantee equal traffic if one popular key receives most requests. Hashing distinct keys cannot remove that popularity by itself.
Possible responses include caching suitable reads, splitting a very busy logical key with a carefully designed sub-key, or changing the model. Each can add aggregation, freshness or write-coordination work. Start with measured request patterns rather than a promise that more shards always solve overload.
Also inspect size and request cost: a few large records or expensive queries can outweigh many small ones. Monitor per-shard latency, traffic, storage and errors.
Rebalancing needs a safe transition
Adding a shard can move some records and traffic to a new owner. Readers and writers need a routing rule during the move so updates do not get lost or diverge. Product-supported migration tools help, but the application must understand relevant limits and failure behaviour.
A simple hash(key) % shardCount rule can remap many keys when the count changes. Production systems may use stable routing maps or other placement schemes to reduce movement. Moving less data does not eliminate migration work.
Cross-shard transactions and joins can require extra coordination. Check the database’s actual guarantees, scope and costs. Plan backup/restore and shard failure; sharding alone does not create redundant copies.
Real partitioning and sharding choices
Representative sources checked 6 October 2026. Measure your key distribution, query patterns and failures; no shard count implies a universal requests/s figure.
PostgreSQL table partitioning
Declarative partitioning divides a table into parts and can let suitable queries avoid irrelevant partitions. Native table partitioning is not by itself a distributed multi-server database. Evaluate it for data management or useful query pruning before introducing distributed storage.
MongoDB sharded clusters
MongoDB sharding distributes data using a shard key. Evaluate query targeting, key distribution, migration and operational complexity. More shards do not repair a poor key automatically.
Amazon DynamoDB partition-key design
The managed service handles storage partitioning, while the application still needs an appropriate partition-key design. Evaluate uneven hot keys, access patterns, consistency and request costs.
Free database software still requires hosting and operation. Managed services reduce some maintenance but do not remove modelling, correctness or cost decisions.
When is the extra complexity justified?
A large history table usually queried by month
Evaluate range partitioning and pruning in the current database first. It may simplify retention or relevant reads without adding a distributed system. Validate that queries actually use the partition boundaries.
Many customers with mostly customer-scoped requests
A customer-based shard key may help target reads and coordinated writes within one owner. Test whether a few unusually large customers dominate traffic and how global reporting will work.
One record gets most of the requests
Adding shards with the same key does not spread that one record’s traffic. Evaluate caching, capacity or a deliberate model change. Choose distributed storage when its gains justify routing, migration and recovery work.
Check your design decision
Check your design decision
Choose the split from the workload
Partitioning divides data; sharding distributes ownership; replication copies data. These can work together but solve different needs.
Pick keys from access patterns, inspect hot records and per-shard load, and plan movement, cross-shard work and recovery. More parts are useful only when the complete design benefits.
Reaching the recap and completing the quizzes are separate milestones.