Skip to main content
Web DevDatabases & CachingDiagramAdvanced

Database Sharding

KO: DB 샤딩 (Database Sharding)·EN: Database Sharding·JA: DBシャーディング(Database Sharding)·Horizontal Partitioning

A horizontal scaling architecture that partitions a large dataset across multiple independent database servers using a shard key to scale writes and storage

Table of Contents

Structure Diagram

Shard-Key Based Horizontal Partition RoutingTap a node
Route QuerBucket 0Bucket 1Bucket 2App / Sha…Hash(tena…Shard 0 (…Shard 1 (…Shard 2 (…
ROOTApp / Shard Router
1 link
Quick Answer

What is Database Sharding?

A horizontal scaling architecture that partitions a large dataset across multiple independent database servers using a shard key to scale writes and storage. It is a core concept in Databases & Caching within Web Dev.

Core Principles

Read replicas and caches scale reads, but write throughput and multi-terabyte storage eventually hit the ceiling of a single database machine. Sharding horizontally partitions rows of a table across multiple independent database nodes (shards) using a Shard Key (such as user_id or tenant_id).

Each shard owns a disjoint subset of the data, allowing total write capacity and storage to scale linearly as nodes are added.

Practical Takeaways

  • Treat sharding as a last resort: Cross-shard JOINs, distributed ACID transactions, global uniqueness, and schema migrations become dramatically harder. Exhaust indexing, caching, read replicas, vertical scaling, and single-node partitioning first.
  • Pick your Shard Key with extreme care: Choose a high-cardinality key aligned with your primary access patterns to avoid hot shards (where one giant tenant overwhelms a single node) and scatter-gather queries.
  • Plan for resharding: Naive id % N hashing forces massive data movement when adding nodes. Use Consistent Hashing, logical virtual buckets, or battle-tested systems like Vitess or Citus.

Notable Examples

  • Slack & YouTube (Vitess): Sharding MySQL by workspace/channel ID to handle millions of concurrent writes.
  • Geo-sharded SaaS: Partitioning customer data by region (US/EU/APAC) to satisfy data residency laws and lower latency.