What is database sharding, and what are its benefits and drawbacks?

Instruction: Define database sharding and discuss its advantages and limitations.

Context: This question assesses the candidate's understanding of sharding as a scalability solution, including when it's appropriate to use and the trade-offs involved.

Updated

Official answer

Sharding distributes different subsets of data across separate database nodes or groups of nodes. For a multi-tenant application, routing by tenant_id can keep most of a tenant's operations on one shard.

Choose the shard key from access patterns and expected skew. Hashing tenants may spread their counts while one very large tenant still overloads its shard. Queries without the routing key may fan out, and cross-shard joins, uniqueness and transactions require explicit support or a different design.

Plan how routing metadata changes during resharding. A move must account for writes in flight, retries and stale routing, with a clear authoritative owner or equivalent coordination. Validate that rows are neither lost nor duplicated, then reconcile before removing the old copy. Globally unique identifiers do not by themselves enforce every global business constraint.

Each shard also needs replication, backup and tested recovery. Losing an unreplicated shard makes its portion unavailable; adding shards alone does not provide high availability. Measure workload skew, fan-out latency, recovery time and operational complexity before adopting sharding or choosing the next split.

Related Questions