Definition
Sharding is horizontal partitioning of a dataset across multiple database nodes: each shard holds a subset of the rows, chosen by a shard key such as user_id. It is the standard answer once a dataset or its write load outgrows a single machine — each node stores and serves only its fraction, so capacity scales with the number of shards.
The shard key is the critical decision, because it determines which queries stay cheap. Queries that include the key route to one shard; queries that do not must fan out to every shard and merge results (scatter-gather). Sharding a posts table by user_id makes per-user timelines fast but makes "latest posts across all users" the most expensive query in the system. Re-sharding live is painful, which is why the key is chosen from the dominant access pattern up front.
How it comes up in interviews
Saying "we'll shard the database" without naming the key is a red flag — the follow-up is always "by what, and what does that make expensive?" Justify the key from the read/write pattern, name the query that becomes scatter-gather, and mention hot-key skew (one celebrity user's shard melting) as the failure mode.