Database Sharding
Subject: Computer and Technology noun /ˈdeɪ.təˌbeɪs ˈʃɑːr.dɪŋ/ 1 definition
- database-systems
- distributed-systems
- data-partitioning
- horizontal-scaling
-
Definition (noun)
Entry #64 · UpdatedDatabase Sharding is a horizontal data-partitioning technique that splits a large logical database into smaller, independent subsets called shards, each hosted on its own database instance or server. Every shard maintains an identical schema while storing a disjoint subset of rows assigned via a shard key, enabling storage capacity and read/write throughput to scale out across multiple nodes rather than relying solely on upgrading a single machine. Unlike database replication, which copies the entire dataset across replicas, or vertical partitioning, which splits tables by column, sharding distributes rows across nodes—trading added complexity in cross-shard joins, distributed transactions, and shard rebalancing for higher write scalability and fault isolation.
Common Types
Range-Based Sharding: Assigns rows to shards according to contiguous intervals of a shard key, such as timestamps, alphabetical prefixes, or numeric ID ranges, making range queries efficient while risking hot shards when writes cluster in the newest range.
Hash-Based Sharding: Applies a deterministic hash function or consistent hashing ring to the shard key to spread rows evenly across nodes, preventing write hotspots while scattering logically adjacent keys across different shards.
Directory-Based Sharding: Maintains an explicit lookup table or metadata service mapping each shard key or tenant to its assigned shard, enabling flexible data placement and smoother rebalancing at the cost of a lookup dependency on the query path.
Geographic Sharding: Places data onto regionally located shards based on geographic attributes such as country or region code, reducing access latency for nearby users and supporting regional data-residency requirements.
Example
An e-commerce platform storing 800 million order records shards its
orderstable across 16 independent PostgreSQL instances by hashingcustomer_idmodulo 16. When customer482910loads their order history, the query router evaluates the hash to targetshard-07directly, querying roughly 50 million rows on that node instead of saturating a single monolithic server.