Datahorizontal partitioningdatabase sharding

Sharding

Definition

Sharding horizontally partitions data across independent nodes (shards), each responsible for a subset of rows chosen by a shard key.

In practice

Sharding scales writes and storage beyond what one machine can hold, which replication alone cannot do. The shard key decides everything: it should spread load evenly and keep data that is queried together on the same shard.

Cross-shard queries, joins and transactions become expensive or impossible, and a poor key creates hot shards. Resharding later is a major migration, so sharding is usually postponed until vertical scaling and read replicas are exhausted.

Example

An orders table is sharded by customer_id across 8 databases, so all of one customer's orders live together and each shard holds about one eighth of the data.