When data outgrows a single server, it is not scaled up but split horizontally: each part — a shard — lives on its own node, and together the parts make up one logical dataset. Both storage capacity and write throughput grow this way: add a node, and part of the data moves onto it.
How it works
| Element | Role |
|---|---|
| Shard key | a field or set of fields whose value decides which part a record goes to |
| Shard | a node or group of nodes that holds its own disjoint part of the data |
| Router | accepts client requests and sends each to the relevant shard or shards |
| Balancer | moves parts of the data between nodes in the background while requests are being served |
Clients do not talk to the nodes directly but to a router: in MongoDB this is the mongos process, in Vitess the vtgate layer. If a request includes the shard key, the router sends it only to the affected shard; if it does not, the router fans it out to every shard and gathers the replies — and the more nodes there are, the more such a query costs.
The shard key is the main decision
The key decides whether data and load are spread evenly and whether a typical query lands on a single shard. A key with monotonically increasing values, such as a date or a counter, sends all writes to one node; high cardinality of a field, that is, many distinct values, does not by itself guarantee an even distribution: how often each value occurs and whether the values grow monotonically matter as well. Changing the key is expensive: re-partitioning a large collection means moving much of the data, so the key is chosen before the load grows.
Where it is used
- MongoDB — sharded clusters: the key is chosen when a collection is sharded, and the balancer moves key ranges between shards
- Vitess on top of MySQL — a routing and sharding layer created at YouTube to scale MySQL
- ClickHouse — a table on a cluster distributes rows across shards, and replicas within a shard keep copies
- Elasticsearch — an index is divided into shards with replica copies
Sources
the term is written from these pagesVerified 9 Nov