Summary

Partitioning splits data into smaller parts. Sharding is horizontal partitioning across different nodes or databases.

Interview Points

  • Partitioning can be logical or physical, vertical or horizontal.
  • Sharding distributes partitions across machines.
  • Shard keys determine load distribution and query efficiency.
  • Bad shard keys create hot shards and cross-shard queries.
  • Rebalancing and resharding are major operational concerns.

2-3 Minute Interview Script

“Partitioning is the general idea of splitting data into smaller pieces. Sharding is a specific form of horizontal partitioning where those pieces live on different nodes.

The most important design choice is the shard key. A good shard key spreads writes and reads evenly while matching common query patterns. A bad shard key creates hot shards or forces expensive scatter-gather queries.

For example, user ID may work well for user-owned data, but timestamp alone may create write hotspots. Sometimes we need composite keys or consistent hashing to improve distribution.

The senior-level answer includes operations: how to rebalance shards, handle growth, migrate tenants, and query across shards when the product needs global views.”

Follow-Ups

  • What makes a good shard key?
  • How do you handle cross-shard queries?