Prerequisites
What it is
Sharding partitions data across multiple databases or nodes. Each shard owns a subset of the data, usually based on a key such as user ID, workspace ID, repository ID, or geographic region.
Why it matters
A single database has limits for storage, write throughput, indexes, and maintenance windows. Sharding lets you add capacity by adding more nodes.
How it works
A routing layer maps each request to the shard that owns its key. Common strategies include hash-based sharding, range sharding, tenant sharding, and directory-based routing.
Hash sharding distributes evenly but makes range queries expensive. Range sharding keeps related data together but risks hot spots. Directory sharding uses a lookup table for flexible mapping at the cost of an extra hop.
When to use it
Use sharding when vertical scaling and read replicas no longer handle write volume, dataset size, or operational isolation needs.
Tradeoffs / failure modes
Cross-shard queries, rebalancing, hot shards, global uniqueness, and transactions become harder. Choosing the wrong shard key is expensive to fix.
Tiny example
Discord can store messages by guild or channel shard so very large communities do not overload one database.
Related guides and systems
See Multi-Tenant Architecture, Feed & Timeline Generation, Full-Text Search, Discord, Slack, Twitter, GitHub, Gmail, and Airbnb.
Seen in deeper dives
Capability
Feed & Timeline Generation
Fan-out-on-write vs fan-out-on-read strategies for personalized content feeds
Capability
Full-Text Search
Inverted indexes, relevance tuning, and search-as-you-type for any content type
Capability
Multi-Tenant Architecture
Shared infrastructure with tenant isolation, noisy neighbor protection, and per-tenant customization
Case Study
Airbnb
A two-sided marketplace for search, booking, payments, and trust
Case Study
Discord
Real-time voice, video, and text for communities at massive scale
Case Study
GitHub
The world's largest code hosting platform powered by Git at scale
Case Study
Gmail
The world's largest email service with AI-powered organization and search
Case Study
Slack
Channel-based messaging for the enterprise workplace
Case Study
Twitter / X
Real-time global public conversation with fan-out at scale
Related concepts
Strong Consistency
Make reads reflect the latest committed write for correctness-critical data.
Write-Through Cache
Keep cache and database updated together so reads can trust the cached value.