Quick Answer
Use horizontal sharding when one dataset outgrows a node’s write or storage capacity, and use vertical sharding to separate independent domains. Do not shard before exhausting query tuning, caching, replicas, larger infrastructure, and native partitioning. Horizontal sharding changes how rows are routed; vertical sharding changes which service or database owns a table or group of columns.
Introduction
Database sharding is a scale-out technique, not a default database design pattern. Horizontal sharding splits rows from the same logical table across servers through a shard key, while vertical sharding separates tables or column groups by functional responsibility. Some guides blur vertical sharding with vertical scaling, even though a larger server is infrastructure scaling rather than data distribution. The expensive part is not splitting data once, but preserving correct routing, operations, and query behavior after the split.
Key Takeaways
Shard only when a single node cannot sustainably absorb required writes or storage.
Choose a shard key that follows dominant reads and distributes writes evenly.
Expect cross-shard operations to become explicit application and operational work.

Database Sharding: Define the Boundaries First
A defensible data sharding architecture starts by separating four concepts that are often treated as synonyms. Horizontal sharding distributes rows of one table across independent database instances. Vertical sharding distributes ownership by table, feature, or column group, such as placing billing data apart from identity data. Vertical scaling upgrades one machine, while database partitioning strategies divide a table inside a single database system.
What to try before sharding
Sharding should be the last structural move because it introduces routing and failure modes that cannot be hidden by a schema diagram. Start with the bottleneck: a slow query needs different treatment from a saturated writer or an oversized index.
Query tuning: Remove wasteful scans and improve index alignment.
Caching: Serve repeat reads without touching the primary database.
Read replicas: Move read traffic away from the writer.
Vertical scaling: Increase compute, memory, or storage on one node.
Native partitioning: Split large tables while retaining one database endpoint.
Partitioning and replication solve different problems
In-database partitioning preserves a single logical database and can simplify retention, pruning, and maintenance, but it does not distribute writes across independent primaries. Replication improves read capacity and availability, whereas sharding vs replication determines whether data itself is distributed. A shard layout distributes portions of a logical dataset across separate database instances, with each shard serving a distinct subset of the data. MongoDB's sharding docs confirm that each shard holds a distinct subset of the data, with clients connecting through a single router rather than any individual shard.[1]
Horizontal Scaling Databases: Select a Routing Model
Horizontal scaling databases require a routing rule that maps each request to the correct shard. The rule should support the access paths the application actually uses, not merely create an even-looking distribution during an early load test. Review the available sharding strategies before selecting a routing scheme, because a scheme that cannot serve the most frequent query without fan-out becomes costly.
Compare horizontal shard distribution strategies
The table below compares common methods by their operational behavior rather than treating any one method as universally correct.
Strategy | Write spread | Range queries | Resharding effort | Hot-spot risk |
|---|---|---|---|---|
Hash | Usually even | Poor | High without indirection | Low for varied keys |
Range | Depends on key pattern | Strong | Moderate | High with sequential keys |
Directory | Policy-driven | Depends on mapping | Mapping updates required | Depends on allocation |
Geographic | Depends on region demand | Strong within region | Data-movement dependent | High for dominant regions |
Consistent hashing | Even with virtual ranges | Poor | Lower movement | Low for varied keys |
Hashing is practical for point lookups, while range distribution supports ordered scans but can concentrate new writes on one shard. Consistent hashing for databases reduces how much data moves when membership changes, yet it does not make range queries local.
Vertical sharding is functional partitioning
Vertical sharding separates domains such as accounts, orders, audit logs, and search metadata into independently owned databases or services. This can fit a microservice boundary and simplify local schemas, but it does not solve the challenge of scaling write-heavy workloads for one massive table. It also replaces local joins with API composition, asynchronous projections, or application-managed queries.

Shard Key Design and the Operational Cost
A shard key should match the application’s dominant access path and distribute write pressure predictably. For multi-tenant systems, tenant ID is often a useful starting point because most requests are tenant-scoped, but one unusually large tenant can still create a hot shard. Avoid monotonic identifiers when new records arrive continuously, because a range scheme can direct fresh writes to the same location.
Keep routing visible in query design
A routed query carries the shard key: SELECT * FROM orders WHERE tenant_id = ? AND order_id = ?. A fan-out query omits it: SELECT * FROM orders WHERE created_at > ?, forcing the system to contact every relevant shard and merge results. Handling cross-shard joins requires denormalized read models, colocated data, or controlled aggregation services rather than assuming distributed SQL behaves like one local join.
Data consistency across multiple shards also requires explicit management. A transaction that updates an invoice and account balance on different shards may need a workflow with idempotency, retries, and compensating actions. Those distributed systems tradeoffs also surface in backups, schema migrations, observability, incident response, and resharding.
Tooling helps with routing, not architecture
Vitess's sharding docs cover distributed database deployments, including keyspaces and resharding.[2] Citus is a PostgreSQL-oriented example that distributes tables and routes queries, but the data model still needs a distribution key that keeps common work local.
DevvPro’s coverage of common sharding mistakes is useful before committing to a routing model, especially when a team is tempted to treat tooling as a substitute for workload analysis.
Make the Decision From Workload Evidence
Use a short decision guide before creating the first shard. Read-heavy services generally benefit first from caching and replicas; storage or write pressure may justify sharding after simpler changes are measured. Regional residency requirements can motivate geographic placement, but regional keys can produce uneven demand.
Questions that expose a premature design
Ask whether the system has a dominant point lookup, whether writes are concentrated around a small set of tenants or records, and whether every production query can include a routing key. Also ask whether the team can operate per-shard backups, migrations, alerting, and recovery. Treat this sharding approach as an operational commitment rather than a one-time schema change.
Keep the comparison honest
Horizontal and vertical sharding are not interchangeable choices. Horizontal sharding addresses a single dataset that needs distribution, while vertical sharding establishes ownership boundaries between different datasets. For a structured review of the terminology, references on database shard architecture distinguish distribution across isolated instances from simpler table partitioning.[3]
Teams can consult DevvPro’s coverage of distributed systems tradeoffs before those tradeoffs become production incidents.

Conclusion
Choose horizontal sharding when measured write or storage demand exceeds what one primary can sustain and requests can reliably carry a distribution key. Choose vertical sharding when separate domains need independent ownership, deployment, and schema evolution, not when one table needs more write capacity. Keep replication, caching, query tuning, vertical scaling, and native partitioning in the design review because they preserve simpler failure and query models. For backend teams making the call, DevvPro offers practical analysis of the routing, consistency, and operational implications of database scale-out.
Most of these mistakes surface early, well before a team actually ships a shard: common early scaling mistakes are worth reviewing before committing to any distribution strategy.
Frequently Asked Questions (FAQs)
What is database sharding and when should you use it?
Database sharding is the distribution of one logical dataset across independent database instances, and it should be used when measured write throughput or storage growth exceeds a single node after query tuning, caching, replicas, larger infrastructure, and native partitioning have been evaluated.
How do you choose the optimal shard key?
The optimal shard key is the value present in the most important request paths, because it routes point reads and writes to one shard while avoiding monotonically increasing values or skewed tenants that concentrate sustained traffic on one location.
What is the difference between horizontal and vertical scaling?
Horizontal scaling adds independent nodes and distributes work among them, while vertical scaling increases the resources of one node, which retains simpler query semantics but eventually reaches infrastructure and operational limits.
What are the common pitfalls of database sharding?
Common database sharding pitfalls include choosing a key that does not match real queries, creating hot shards, allowing uncontrolled cross-shard fan-out, and underestimating the operational work required for migrations, backups, recovery, and monitoring.
How do developers handle data rebalancing after sharding?
Developers handle data rebalancing by moving bounded key ranges or mapped tenants between shards, validating reads and writes during the transition, and retaining idempotent migration steps so retries do not duplicate or lose records.
Why does sharding create difficulties for complex queries?
Sharding creates difficulties for complex queries because joins, aggregates, sorting, and transactions that lack a shared routing key can require work on multiple shards, followed by application or middleware coordination to merge results correctly.
Sources
- Sharding — MongoDB Docs — MongoDB ↩
- Sharding | Vitess — vitess.io ↩
- Shard (database architecture) - Wikipedia — en.wikipedia.org ↩


