SeniorDatabases

What is database sharding, when do you need it, and what are the trade-offs?

What they are really testing: Senior signal: knows sharding scales writes/storage past one machine, treats it as a last resort after simpler options, and can name the hard parts (shard key, cross-shard queries, hotspots, rebalancing).

A real interview question

What is database sharding, when do you need it, and what are the trade-offs?

What most people say

drag me

Sharding splits the database across servers so it can handle more load.

Right definition but no judgment. A senior answer notes sharding is a last resort after replicas/caching, that it scales writes (not just load), and names the real costs: shard-key choice, cross-shard queries, hotspots, and resharding pain.

The follow-ups they ask next

  • What makes choosing a shard key so important?

    It determines load distribution: a bad key creates hotspots (one shard overloaded) and forces many queries to hit all shards. It is also very hard to change later, so it has to match the dominant access pattern from the start.

  • What should you try before sharding?

    Vertical scaling (bigger instance), read replicas for read load, caching to offload reads, and query/index optimization. Shard only when write throughput or dataset size genuinely exceeds a single node, since it adds large complexity.

What the interviewer is listening for

  • Sharding = horizontal partition by key, scales writes/storage
  • Treats it as last resort after replicas/caching
  • Names shard-key/hotspots/cross-shard/resharding costs

What sinks the answer

  • Jumps to sharding for any load
  • Thinks it is the same as read replicas
  • No mention of shard-key or cross-shard pain

If you genuinely do not know

Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.

Sharding is [horizontal partitioning across nodes by a shard key, scaling writes and storage past one machine]. Need it [when write throughput or dataset size exceeds a single primary, what replicas/caching cannot fix]. [Try vertical scaling, replicas, and caching first, it is a last resort]. Trade-offs: [shard-key choice/hotspots, expensive cross-shard queries, cross-shard transactions, painful resharding].

Keep going with databases

All 336 cloud engineer questions

Knowing the answer is not the same as recalling it under pressure

Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.

Start free