Sharding vs Partitioning
Question Variations
- "What is the difference between horizontal partitioning and sharding?"
- "When would you choose to shard a database instead of just vertically scaling the server?"
- "What are the common challenges when performing joins across shards?"
- "How do you handle 'hotspots' in a sharded database architecture?"
Why This Is Asked
This question reveals whether you can design databases for scale. Interviewers want to see that you understand the difference between splitting data within a single database (partitioning) and across multiple database servers (sharding), and that you can articulate the operational complexity each introduces.
Key Concepts
- Partitioning splits a table into smaller pieces within the same database instance (horizontal or vertical)
- Sharding distributes data across multiple independent database servers using a shard key
- Sharding enables horizontal scaling beyond a single machine’s limits but introduces cross-shard query complexity
- Cross-shard joins and distributed transactions are expensive and often require denormalization
- Shard key selection is critical: poor keys create hotspots, good keys distribute load evenly
Question Variations
- “What is the difference between horizontal partitioning and sharding?”
- “When would you choose to shard a database instead of just vertically scaling the server?”
- “What are the common challenges when performing joins across shards?”
- “How do you handle ‘hotspots’ in a sharded database architecture?”