Q12: What is database sharding, and when is it useful?
Sharding horizontally partitions rows across multiple database nodes, often by a shard key such as tenant ID or user ID. It can increase storage and write capacity, but introduces routing, rebalancing, cross-shard queries, distributed transactions, and hotspot risks. Choose a key with high cardinality and even distribution that matches common access patterns; plan how to change the key or add shards later.
Key Takeaways
- A good shard key distributes load and supports frequent queries.
- Sharding adds operational and query complexity; do not do it prematurely.