Skip to main content
New: 9 PM Courses with hands-on exercises and certificates
Back to Glossary
EngineeringD

Database Sharding

Definition

Database sharding is a horizontal partitioning strategy where a single logical database is split across multiple physical servers (shards), with each shard storing a distinct subset of the data. Instead of one database server holding all 100 million user records, a sharded system might distribute them across 10 servers, each holding 10 million records. The application or a routing layer determines which shard to query based on a shard key (typically user ID, tenant ID, or geographic region).

Sharding differs from replication, which copies the same data to multiple servers for redundancy and read scaling. With replication, every server has all the data. With sharding, each server has different data. Many production systems use both: each shard is replicated for durability, but data is partitioned across shards for write scaling. Instagram, Pinterest, Uber, Slack, and Notion all use sharded databases. Vitess (developed by YouTube for MySQL) and Citus (for PostgreSQL) are popular sharding middleware that add sharding capabilities to standard relational databases.

The fundamental tradeoff is scalability versus complexity. A single database server is simple: any query can access any data, transactions work across any records, and schema migrations are a single operation. Once you shard, every one of these becomes harder. Queries that span multiple shards are slow. Transactions across shards require distributed coordination. Migrations must be applied to every shard independently. This is why experienced engineers treat sharding as the scaling option of last resort, after exhausting caching, read replicas, query optimization, and microservices decomposition.

Why It Matters for Product Managers

Sharding decisions affect product capabilities and roadmap timelines. Once a database is sharded by user ID, features that require querying across all users (global leaderboards, admin search, cross-tenant analytics) become significantly more expensive to build and slower to run. PMs need to understand the shard key because it determines which queries are fast (single-shard, following the shard key) and which are slow (cross-shard, requiring fan-out to every shard).

For PMs at high-growth products, sharding conversations typically arise when the database becomes a bottleneck. The engineering team will describe symptoms: slow queries, replication lag, storage limits, or write contention. The PM's role is not to choose the sharding strategy but to understand the product implications. Ask: "What features become harder to build after we shard?" and "How does this affect our roadmap for the next two quarters?" Sharding projects typically take 3-6 months for a skilled team and require significant testing. Plan roadmap commitments accordingly.

How to Apply It

If your engineering team is evaluating sharding, PMs should contribute to the shard key decision. The shard key determines data co-location: records that share a shard key are on the same server and can be queried together efficiently. For a B2B SaaS product, sharding by tenant ID is common because most queries are within a single tenant's data. For a consumer product, sharding by user ID is typical. Ensure the shard key aligns with how the product actually queries data. A poor shard key choice means rebuilding the sharding scheme later, which is one of the most painful database operations. Consult your technical product manager to evaluate the tradeoffs and timeline implications before committing the engineering team to a multi-month infrastructure project.

Frequently Asked Questions

When should a product team consider database sharding?+
Sharding should be a last resort, not a first step. Consider it when: (1) your single database server is at capacity and vertical scaling (bigger hardware) is no longer cost-effective or possible; (2) your dataset exceeds what a single server can store; (3) your read/write throughput exceeds what a single server can handle even with read replicas and caching. Most products never need sharding. Instagram served 30 million users on a single PostgreSQL server before sharding. Pinterest waited until they had tens of millions of users. Premature sharding adds enormous complexity for no benefit.
What are the main sharding strategies?+
The three common strategies are: range-based (shard by date range, user ID range, or alphabetical range), hash-based (apply a hash function to the shard key to distribute data evenly), and directory-based (maintain a lookup table mapping each record to its shard). Hash-based is most common because it distributes data evenly. Range-based is useful when queries naturally filter by the range dimension (e.g., time-series data). Directory-based offers maximum flexibility but introduces a single point of failure in the lookup service.
What are the biggest operational challenges of sharding?+
Cross-shard queries are the most painful challenge. If data is sharded by user ID and you need to run an analytics query across all users, you must query every shard and merge results. Rebalancing (adding or removing shards) requires moving data between servers with minimal downtime. Schema migrations must be applied to every shard. Backup and recovery become per-shard operations. Monitoring complexity multiplies by the number of shards. These operational costs are why most companies exhaust every other scaling option before sharding.

Explore More PM Terms

Browse our complete glossary of 100+ product management terms.