Data & storage

Sharding (Horizontal Partitioning)

Sharding splits a dataset across multiple machines so each holds a subset, letting writes and storage scale beyond the ceiling of a single box.

In technical terms

The key choice encodes a prediction: hash partitioning distributes evenly and makes point reads local but scatters joins and fan-outs; range partitioning serves scans and grouping with a hot-tail risk at the boundary; directory/hybrid routing buys flexibility at one hop. Cross-shard casualties: uniqueness, joins, transactions, rebalancing, and ordering.

-- hash by tenant_id: even spread, tenant-scoped queries local
-- range by created_at: time-window scans, newest shard runs hot
-- composite (tenant, time): both good, key choice now a design decision

Why it appears in interviews

Every “it grew 100x” design asks who pays first: the shard-key question is the interview version of “what is your access pattern,” and the answer is graded on the losses you name, not the vocabulary you list.

The common misconception

That sharding is the first answer. Replicas, caching, schema and query work usually buy 10-100x before the pain is earned, and saying so unprompted is the senior move.

Trade-offs & when it hurts

Name the casualties and the plan: global uniqueness moves to the app or a routing table; cross-shard transactions become sagas or idempotent workflows; the whale tenant gets a dedicated shard or sub-keys. Migration needs the boring machinery: dual-write, backfill, read-cut, and a rollback that is not an act of faith.

How to show it in an interview

Close the sharding answer with the accepted losses: “I shard by tenant_id. Every tenant query is local; cross-tenant analytics move to a change-feed replica, global uniqueness moves to a lookup table, and one whale gets its own shard with a routing rule on top. The migration is dual-write, backfill, verify counts, cut reads. Rollback is flipping reads back for one day of lag debt.” Losses named, migration rehearsed: that is a senior hire.

Questions this concept earns

  • Pick the key for a multi-tenant SaaS growing 10x a year. Then break it: which single tenant is 10% of traffic?
  • A report needs rows from six shards: is that the key’s problem or yours?
  • Design the migration: the cutover window, the verification query, and the rollback you can live with.

Use the concept in a real session

Answer follow-up questions about sharding (horizontal partitioning) and related systems, and get a scored report in minutes.

Related

Last reviewed: 2026-09-03 by MockWise Engineering · Corrections welcome via contact.