.NET Architecture & System Design Interview Question #59

What is database sharding?

Database Scaling, Partitioning, NoSQL & Data Consistency Mid-Level Intermediate

Quick Interview Answer

Sharding distributes portions of a logical dataset across multiple independent database nodes. Each shard owns a subset of the data, commonly selected by tenant, customer, geographic region, or a hash of a key.

Detailed Explanation

Sharding distributes portions of a logical dataset across multiple independent database nodes. Each shard owns a subset of the data, commonly selected by tenant, customer, geographic region, or a hash of a key.

Sharding can increase write and storage capacity beyond one server, but it introduces routing, rebalancing, cross-shard query, transaction, operational, and recovery complexity.

Code Example

Shard key: CustomerId

Customer 1 -> Shard A
Customer 2 -> Shard B
Customer 3 -> Shard C