Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Sharding Planner

A database sharding planner. Enter your total data size and query rate, and what a single shard can hold and serve, and get the number of shards you need — the larger of the storage and throughput requirements, with growth headroom — plus the per-shard load and a reminder of what resharding later costs.

12shards recommendedbound by storage
By storage12
By throughput9
Per shard333 GB · 10.0k QPS
With ×3 replicas36 nodes

Sharding is what you do when one machine can no longer hold your data or serve your traffic, and the shard count comes from whichever of those two walls you hit first. This planner sizes both walls with headroom, takes the larger, and shows what each shard and the whole cluster then carry.

What it computes

utilization    = 1 − headroom / 100         at least 0.05
by storage     = ⌈ total data / (per-shard GB × utilization) ⌉
by throughput  = ⌈ total QPS / (per-shard QPS × utilization) ⌉
shards         = max(1, by storage, by throughput)
per shard      = total data / shards  and  total QPS / shards
nodes          = shards × replication factor
  • Per-shard capacity is the data one shard can hold and the queries per second it can serve at its limit, measured or taken from benchmarks of your own setup.
  • Headroom is the share of each limit you refuse to use, kept for spikes, skew and growth.
  • Bound by names the requirement that set the count. A tie is reported as storage.
  • Replication factor copies every shard, multiplying machines but not the shard count.

A worked example

The defaults are 4,000 GB of data and 120,000 QPS, with shards that hold 500 GB and serve 20,000 QPS, 30% headroom and 3 replicas.

  1. Utilization: 1 − 0.30 = 0.7, so each shard is planned to 350 GB and 14,000 QPS.
  2. By storage: 4,000 / 350 = 11.4, rounded up to 12.
  3. By throughput: 120,000 / 14,000 = 8.6, rounded up to 9.
  4. Shards: max(12, 9) = 12, bound by storage.
  5. Per shard: 4,000 / 12 = 333 GB and 120,000 / 12 = 10.0k QPS, which is 67% of the disk limit and 50% of the query limit.
  6. With 3 replicas: 12 × 3 = 36 nodes.
ChangeBy storageBy throughputShardsBound by
Defaults12912storage
No headroom868storage
QPS doubles to 240,000121818throughput
Shards hold 1,000 GB699throughput

The last two rows show why both walls matter: fix the binding one and the other takes over.

Assumptions and limits

  • Perfectly even spread. Every shard gets the same data and load. Real key distributions are skewed, and one hot key can saturate a shard on its own.
  • Primaries do all the work. Read replicas that serve traffic are not credited, and write and read costs are not separated.
  • Today’s numbers. There is no growth rate; plan with the data and traffic you expect at the end of the period, not now.
  • Capacity is yours to supply. Per-shard limits depend on hardware, schema, indexes and query mix, so benchmark them.

How to use the result

  • Pick a count you can grow from. Many systems create more logical partitions than machines, for example several per node, so adding hardware moves whole partitions instead of rehashing keys.
  • Watch the binding limit. It is the metric to alert on and the one that triggers the next expansion.
  • Choose the shard key before the count. High cardinality and even access matter more than any number this tool produces.
  • Leave the migration budget. Resharding adds load while data moves, so start expanding while headroom remains.

When to use it, and when not

Use it at the start: when a proposal says “we need sharding”, to check whether one machine really is out of room, and to pick a first shard count you can defend. Enter 300 GB and 10,000 QPS with the other defaults and both requirements come to 1: a single primary with replicas still fits, and sharding would only add cross-shard queries and operational cost. It is also a quick sanity check on a cluster size someone else proposed.

Measure instead when you already know access is skewed, when queries routinely touch many shards, or when you are choosing between engines. The count assumes every query lands on exactly one shard and every shard gets the same share. Once either stops being true, a load test with your production key distribution tells you more than any formula.

Trade-offs and limits

Three things the model leaves out can each break the plan on their own.

  • Hot keys. In the diagram, one key carries 6,000 of the default 120,000 QPS. The other 114,000 spread over 12 shards at 9,500 each, so the hot key’s shard runs at 15,500: past the planned 14,000 while the cluster average is 10,000. Doubling to 24 shards brings that shard down to 10,750, but a single key above 20,000 QPS saturates its shard at any count. It has to be split or cached.
  • Scatter-gather queries. A query that cannot be routed by the shard key goes to every shard. If 5,000 of the 120,000 QPS are like that, they cost 5,000 × 12 = 60,000 shard queries, so each shard serves (115,000 + 60,000) / 12 = 14,583 QPS, over its planned 14,000. More shards do not help: every shard still sees all 5,000.
  • Resharding cost. With hash(key) mod N, going from 12 to 13 shards moves about 92% of keys, 12 in every 13. Consistent hashing moves about 1 in 13, roughly 7.7%.
Ignored by the modelEffect on the real count
Key skew, hot keysThe hottest shard, not the average, sets the limit: need more
Fan-out queriesEvery shard serves all of them, at any count: change the key or the query
Replicas serving readsRead capacity multiplies: may need fewer
Growth during the planToday’s numbers undershoot: need more

Common mistakes

  • Sizing to the average shard. Plans and alerts built on cluster-wide utilization miss the one shard that is hot. Watch the busiest shard, and size so that it, not the mean, stays under the line.
  • A low-cardinality shard key. Sharding by country or plan tier gives a handful of possible values, so a few shards get most of the data however many you create. A key with millions of distinct values spreads; a key with ten does not.
  • Using raw disk as per-shard GB. Indexes, write-ahead logs, compaction space and the free space a database needs to run all come out of the same disk. Enter usable data capacity, which is well below the drive size.
  • Counting replicas as write capacity. Every write still goes to one primary per shard and is then copied. Replicas add read throughput and durability, never write throughput.
  • Resharding at the limit. Moving data costs disk and network on the very shards that are full. Start when the binding metric reaches the planned line, not the hard one.

Check yourself

You hold 9,000 GB at 60,000 QPS, with the default 500 GB / 20,000 QPS shards, 30% headroom and 3 replicas. How many shards and nodes, and what binds?

Storage: 9,000 / 350 = 25.7, so 26. Throughput: 60,000 / 14,000 = 4.3, so 5. The plan is 26 shards bound by storage, and 26 × 3 = 78 nodes. Each shard serves only about 2,300 QPS, so bigger disks per shard would cut the count far more than faster machines.

Keep the defaults but raise headroom from 30% to 50%. What changes?

Utilization drops to 0.5, so each shard is planned to 250 GB and 10,000 QPS. Storage needs 4,000 / 250 = 16 and throughput 120,000 / 10,000 = 12. The plan grows from 12 to 16 shards and from 36 to 48 nodes, still bound by storage.

Your cluster routes with hash(key) mod N over 12 shards. Roughly what share of keys move if you add one shard, and if you double to 24?

A key stays only if its hash leaves the same remainder mod 12 and mod 13, which happens for about 1 key in 13, so about 92% move. Doubling to 24 keeps exactly the keys whose remainder mod 24 is below 12: half stay, half move. That is why systems that use mod N grow by doubling.

One celebrity account receives 25,000 QPS. How many shards fix it?

None. Every request for one key goes to one shard, and 25,000 is more than the 20,000 a shard serves at 100%, let alone the 14,000 planned. The fix is to change the key, for example spreading that account’s data across sub-keys, or to absorb its reads in a cache in front of the shard.

hash(key) → 12 shards: QPS on each20.0kper-shard limit12345678910111214.0kplanned 70%15.5khot key +6.0k9.5kshard
The default plan with one hot key, drawn to scale. The formula assumes every shard carries the average, 10,000 QPS; a key worth 6,000 QPS lands on one shard and lifts it to 15,500, past the planned 70% line.

How it works

  • Shards = max(storage need, throughput need), each sized with headroom.
  • Shows which limit binds and the per-shard data and QPS you commit to.
  • Nodes = shards × replication factor.
  • Consistent hashing limits, but never eliminates, data movement on resharding.

Frequently asked questions

How many shards do I actually need?

The larger of two requirements. Storage: total data divided by how much one shard can hold. Throughput: total queries per second divided by how many one shard can serve. You need enough shards to satisfy both, so the answer is the maximum of the two, after leaving headroom on each. With this tool’s defaults, 4,000 GB needs 12 shards by storage and 120,000 QPS needs 9 by throughput, so the plan is 12, bound by storage.

Why add headroom instead of sizing exactly?

Because shards running near full capacity have no room for traffic spikes, uneven key distribution, where some shards always run hotter than others, or growth before new capacity arrives, and adding shards is disruptive. Planning each shard to about 60 to 70% of its limit gives breathing room and delays the next resharding. The tool divides each limit by one minus the headroom, so the default 30% means planning to 70% of capacity.

Why is resharding so costly?

When the number of shards changes, the mapping from keys to shards changes, so a large fraction of the data has to move between machines while the system stays online. That is slow, adds load at the worst moment and is easy to get wrong. Consistent hashing or a fixed set of many small partitions reduces how much moves, to roughly one new shard’s share of the keys, but never to zero. Plan the count with headroom instead of resharding under pressure.

How do I keep shards balanced?

Choose a shard key with high cardinality and even access, so data and load spread uniformly; a key such as user ID usually beats something skewed such as country. Watch for hot keys, such as a celebrity account or a viral item, that can overwhelm one shard regardless of how many there are; those need special handling such as splitting the key or caching it. This planner sizes the count, and the shard key decides whether each shard really carries its share.

Do replicas count toward shard capacity?

Not in this calculation. The shard count is sized as if each shard’s primary holds its data and serves its share of the queries, and replication then multiplies the number of machines: 12 shards with three copies each is 36 nodes. If your replicas serve reads, the real throughput per shard is higher and you may need fewer shards for a read-heavy workload. Writes still go to one primary per shard, so size write-heavy systems as the tool does.