Sharding
Description
Sharding partitions a single logical dataset across multiple physical stores by applying a key function to each record. Each shard holds a disjoint slice of the data; reads and writes are routed to the owning shard via the same key function. The structural move is “split then route” — and the choice of key function is the load-bearing decision, because it determines both the routing logic and the failure modes (hot shards, cross-shard transactions, resharding pain). The diagnostic shape distinguishes sharding from related concepts: replication duplicates (same data, multiple stores, redundancy); sharding splits (different data, multiple stores, scale). The two co-occur in practice — most production systems are sharded and replicated within each shard — but solve different problems.Triggers
User-initiated: User describes a system that can’t fit on a single store (capacity, throughput, or fault-domain), or describes a per-tenant / per-region / per-customer split. Vocabulary cues: “shard,” “partition,” “horizontal scale,” “split by key,” “per-tenant DB.” Agent-initiated: Engine notices a system whose capacity ceiling is the single-store ceiling, or whose latency profile shows tail-latency dominated by one hot subset of data. Candidate inference: “this dataset wants to be sharded — what’s the key function, and does it distribute uniformly?” Situation-shape signals: Single-store capacity exhausted; per-tenant isolation needed; geographic distribution required; need to scale writes (not just reads — which is what replication solves).Exclusions
- Single-store fits comfortably — sharding is premature; the operational complexity (resharding, cross-shard transactions, routing layer) doesn’t earn its keep.
- Most queries cross shards — if the access pattern doesn’t align with the shard key, every query fans out to all shards; you’ve paid sharding’s cost without earning its benefit.
- Strong cross-shard ACID required — distributed transactions across shards are expensive and operationally fragile; a single store with vertical scaling may be the cheaper answer until you’re forced off it.
Structure
Relationships
- replication — sharding + replication is the standard distributed-storage pattern: split for scale, replicate within each shard for redundancy.
- grain — the shard key is a grain choice; wrong grain → hot shards or cross-shard pain.
- load-balancing — uniform key distribution = uniform load; non-uniform key → load-balancing problem reappears at the shard level.
- multi-hop-routing — the router is the always-traversed hub between client and shard.
Examples
Database partitioning · computer-science
Database partitioning · computer-science
Library card catalogs (pre-digital) · library-and-museum-studies
Library card catalogs (pre-digital) · library-and-museum-studies
CDN edge caches · computer-science
CDN edge caches · computer-science
Cell biology · biology
Cell biology · biology
DeCandia et al., *Dynamo: Amazon's Highly Available Key-value Store* (SOSP 2007) — consistent hashing as the routing fun · computer-science
DeCandia et al., *Dynamo: Amazon's Highly Available Key-value Store* (SOSP 2007) — consistent hashing as the routing fun · computer-science
Federalism in government · political-science
Federalism in government · political-science
Kleppmann, *Designing Data-Intensive Applications* (2017), Chapter 6 — the canonical engineering reference. · computer-science
Kleppmann, *Designing Data-Intensive Applications* (2017), Chapter 6 — the canonical engineering reference. · computer-science
Microservices with per-service databases · computer-science
Microservices with per-service databases · computer-science
Vitess (YouTube's MySQL-sharding layer) — open-source instance of router-as-distinct-layer. · computer-science
Vitess (YouTube's MySQL-sharding layer) — open-source instance of router-as-distinct-layer. · computer-science
vtgate) sitting between clients and the underlying MySQL shards (vttablet-fronted instances). Clients speak the standard MySQL wire protocol to vtgate, which parses queries, consults the schema-aware routing rules (which tables are sharded by which keysspace + vindex), fans queries out to the right shards, and recombines the results. Schema changes, resharding (splitting hot shards), and cross-shard transactions are all coordinated through this routing layer rather than baked into the application code. The architecture makes the shard-key choice and the routing logic first-class, debuggable artifacts rather than ad-hoc client-side conditionals scattered through the application.Inference: When sharding becomes load-bearing for a system’s scale, making the router its own component pays for itself through what it makes visible: hot-shard diagnostics, resharding orchestration, cross-shard query planning, and per-tenant routing rules all become operations against a single addressable surface rather than archaeology across application code. The Vitess design also surfaces the inverse warning — if the access pattern doesn’t align with the shard key (most queries cross shards), the explicit router still serves them, but every query becomes a fan-out and the system pays sharding’s cost without earning its benefit. The router-as-layer move only pays off when most queries route to a single shard via the key; when they don’t, the diagnostic is to revisit the key function, not to optimize the router.