Sharding Patterns Compared: What Actually Fits Your Data
Sharding gets reached for once a single database can no longer handle the load, but the strategy you pick shapes years of future engineering work, not just the migration itself. The four common patterns, sharding by tenant, by range, by hash, and by function, trade off differently on query complexity, rebalancing pain, and how evenly load actually spreads. Here's what each one actually costs you.
When does sharding by tenant fit best?
Splitting data so each customer or organization's data lives in a specific shard maps naturally onto how most B2B products already query data, since almost every request is already scoped to one tenant. The tradeoff shows up with uneven tenant sizes: a handful of large customers can outgrow a single shard while hundreds of small ones sit mostly idle on others, which means you'll eventually need a plan for splitting an oversized tenant or migrating it to dedicated infrastructure.
When does range sharding break down as data grows unevenly?
Splitting data by a range, dates, alphabetical customer names, sequential IDs, is straightforward to reason about and makes range queries efficient, since related data tends to sit physically close together. The failure mode is hot spotting: if new data is always written to the most recent range, that one shard absorbs a disproportionate share of write load while older shards go quiet, which defeats the purpose of spreading load in the first place. This pattern works best when you can predict and actively manage how ranges grow, not when growth is unpredictable.
Hash sharding spreads load evenly but breaks range queries
Hashing a key, a user ID or an order ID, to pick a shard distributes both storage and write load close to evenly regardless of how the underlying data grows, which solves the hot spotting problem range sharding runs into. The cost is that any query needing a range or an ordered scan across the sharded key now has to fan out across every shard and merge results, since hashing intentionally scatters related values. This pattern fits access patterns that are almost always single key lookups, and fits poorly with anything that wants sequential or range access.
Functional sharding separates by workload, not by key
Splitting by function, keeping your write heavy transactional tables on one database and read heavy analytics or reporting data on another, addresses a different problem: contention between very different workloads competing for the same resources. This doesn't solve the scaling problem within either workload on its own, and it's often combined with one of the other three patterns applied within a given functional split once that split alone stops being enough.
Zero-trust access control gets more complex with every shard added
Each shard is a separate access surface that needs its own authentication, connection credentials, and audit logging, and a query spanning shards needs a coordination layer that itself becomes a piece of infrastructure worth securing carefully, since it typically has broader access than any single shard does on its own. Map out how access control and audit logging will work across shards before you commit to a pattern, not after the migration, since retrofitting consistent access control across an already sharded system is considerably harder than designing it in from the start. Give that coordination layer the same scrutiny you'd give any service holding broad read access, since it's effectively a new privileged component.
Pick based on your actual access pattern, not what's currently popular
The right pattern follows directly from how your application actually queries data: mostly single tenant scoped, mostly single key lookups, mostly range scans, or a workload split. Write down your top ten most frequent query patterns before choosing, and test the candidate sharding scheme against those specific patterns rather than against a generic benchmark, since the pattern that wins on paper can still fail badly against your particular access shape. Revisit the choice if your query patterns shift meaningfully as the product grows, rather than assuming the original decision holds forever.
For example, suppose a B2B invoicing product lists its ten most frequent queries and finds that nearly all are scoped to one customer, with only an occasional report scanning by date. Tenant sharding fits the first group, and the date report can run against a separate read copy. A team that picked hash sharding because it spreads load evenly would then pay a fan-out cost on almost every report. The common mistake is choosing on theory. Test the candidate against your own list, and note which queries would cross shards.
How to match a pattern to your access pattern:
- Choose tenant sharding when almost every request is scoped to one customer, and plan ahead for a tenant that outgrows its shard.
- Choose range sharding when growth is predictable and range queries matter, and watch for hot spotting on the newest range.
- Choose hash sharding for mostly single key lookups, accepting that range queries must fan out across every shard.
- Choose functional sharding to separate write heavy transactional tables from read heavy analytics data.
- Map access control and audit logging across shards before committing to any pattern.
What Good Looks Like
A good sharding choice matches your actual top query patterns, has a defined plan for uneven growth across shards, and includes access control and audit logging designed for a multi-shard system from the start.
Building The Capability (5-Stage Skill Ladder)
How to Get Started
Frequently Asked Questions
Which sharding pattern is easiest to implement for a typical B2B SaaS product?
Sharding by tenant usually fits best, since most B2B queries are already scoped to a single customer or organization. The main thing to plan for in advance is what happens when one tenant outgrows a single shard.
Why does hash sharding break range queries?
Hashing intentionally scatters related keys across shards to spread load evenly, which means a query that wants a range or an ordered scan has to fan out across every shard and merge results instead of reading from one place sequentially.
Do we need to shard our database before we have a real scaling problem?
No, sharding adds real operational and access control complexity, so it's worth delaying until a single database genuinely can't handle load through simpler means like read replicas, indexing, or query optimization. Sharding early, before you understand your real access patterns, tends to lock in the wrong scheme.
About the numbers
This guide doesn't quote a sourced benchmark. Figures in it are estimates or general guidance, so check them against your own numbers.
Related Guides
Continuous Device Verification for a Zero-Trust API
How continuous device and identity verification actually works in a zero-trust architecture, and where to draw the line for a small engineering team.
Rolling Out Zero Trust in Production Without a Broad Outage
A checklist for rolling out stricter API authentication and authorization in production, and the pitfalls that turn a rollout into an incident.
When Your Database Actually Needs Sharding, and When It Doesn't
A decision framework for whether to shard a growing database, the cheaper fixes to rule out first, and what sharding costs you once it's live.
How to Audit Whether Your APIs Actually Enforce Zero Trust
A step-by-step method for testing whether your APIs enforce zero trust in practice, not just on paper, and what to do with what you find.
Choosing a Sharding Key: The Criteria That Matter More Than the Technology
A decision guide for picking a database sharding key, focused on the access pattern criteria that determine whether sharding helps or hurts.
The Real Latency Cost of Zero Trust, and How to Measure It
How to find out how much latency your zero trust controls actually add, which checks are worth the cost, and which ones you can move off the hot path.