Skip to content

Sharding vs Partitioning vs Replication

CoreConceptJuly 21, 20267 min read

A team says "we need to shard the database" when the actual measured problem is a 200GB events table that scans slowly, or "let's add replication" when what they really mean is "split this table by month." These three words get used almost interchangeably in casual conversation, but they answer three different questions — and a real large-scale system usually runs all three at once, not one instead of another.

This guide draws the line precisely: partitioning splits one table into pieces inside one database; sharding splits a dataset across independent databases; replication copies the same data for availability and read scaling. It compares the three replication topologies (leader-follower, multi-leader, leaderless), then focuses on the part teams get wrong most expensively: choosing a sharding key. For matching a scaling technique to a measured bottleneck, see Database Scaling Techniques; for the read/write quorum mechanics behind leaderless replication, see Quorum Reads and Writes.

Three axes: split a table, split a dataset, or copy data
Three axes: split a table, split a dataset, or copy data

Three Axes, Not Three Alternatives

Partitioning divides one large table into smaller physical pieces — by range, list, or hash — while it all still lives in one database with one primary for writes. Sharding divides an entire dataset across multiple independent databases, each a separate failure domain with its own storage and often its own primary. Replication makes copies of the same data, on separate nodes, for availability and read capacity — it doesn't divide anything, it duplicates.

A large real system commonly runs all three together: a dataset sharded across twenty databases by tenant ID, where each shard's largest table is itself partitioned by month, and each shard is also replicated for failover. Asking "should we shard or replicate?" is often the wrong question — the right one is "which axis does our measured bottleneck actually sit on?"

These compose: sharded + partitioned-per-shard + replicated-per-shard
These compose: sharded + partitioned-per-shard + replicated-per-shard

Quick reference

  • Partitioning: one database, table split into smaller physical pieces — no new failure domain.
  • Sharding: dataset split across independent databases — each shard is its own failure domain.
  • Replication: the same data copied across nodes — for availability and read scaling, not for splitting anything.
  • These compose: a sharded system's shards are commonly both partitioned internally and replicated for failover.
  • A bottleneck on scan time within one huge table is a partitioning question; a bottleneck on total write throughput across the whole dataset is a sharding question; a bottleneck on read capacity or availability is a replication question.

Remember this

Partitioning splits a table, sharding splits a dataset across databases, and replication copies data for availability — a production system usually needs more than one of these at once, not a single choice between them.

Partitioning and Sharding: Same Split, Different Scope

The mechanism looks similar — both divide data by a key — but the scope is the entire distinction. A partitioned table still has one primary; a query that needs data from two partitions is one local query the planner prunes automatically. A sharded dataset has no single primary at all; a query that needs data from two shards means the application (or a routing layer) issuing two separate queries to two separate databases and combining the results itself — there is no query planner spanning shards.

That's why partitioning is usually the earlier, cheaper move: it solves "this one table is too large to scan efficiently" without introducing cross-database routing, rebalancing, or the loss of cross-row transactions that sharding brings. Reach for sharding only when write throughput or total storage exceeds what one database (even a well-partitioned one) can hold — see Database Scaling Techniques for the bottleneck-matching decision in full.

Partitioning stays inside one planner; sharding has no cross-database planner
Partitioning stays inside one planner; sharding has no cross-database planner

Quick reference

  • Partition pruning happens inside one query planner — sharding has no equivalent, cross-shard reads are the application's problem.
  • Partitioning preserves single-database transactions and joins; sharding gives those up for cross-shard operations.
  • Partitioning first, sharding later is the common order — sharding adds operational cost partitioning does not.
  • A sharded system typically partitions internally too — the two are not mutually exclusive, they operate at different scopes.
  • Neither partitioning nor sharding by itself adds redundancy — that's replication's job, layered on top of either.

Remember this

Partitioning stays inside one query planner's reach; sharding gives that up entirely — which is why partitioning is usually the cheaper first move and sharding the more expensive later one.

Replication Topologies: Leader-Follower, Multi-Leader, Leaderless

Leader-follower (the most common) has one node accept all writes and stream them to followers, which serve reads. Failover requires promoting a follower to leader — and anything written to the old leader but not yet replicated at the moment of failure is at risk of loss, exactly the trade-off Active-Active vs Active-Passive Architecture covers in depth.

Multi-leader lets more than one node accept writes — usually one leader per data center, replicating to the others. This avoids a single node bottlenecking writes globally, at the cost of needing conflict resolution when the same record is written in two places before either replication catches up. Leaderless (Dynamo-style) has no leader at all: any replica can accept a write, and reads/writes use configurable quorums to stay consistent enough — the exact mechanism Quorum Reads and Writes walks through, including sloppy quorums and read repair. Choosing between these three is really choosing how you want to handle the moment two writes to the same data disagree — a leader-follower system prevents the disagreement by construction (one writer), while multi-leader and leaderless systems accept it can happen and define how to reconcile it after the fact.

Three answers to: what happens when two writes to the same data disagree?
Three answers to: what happens when two writes to the same data disagree?

Quick reference

  • Leader-follower: simplest to reason about, single write bottleneck, failover risks losing unreplicated writes.
  • Multi-leader: removes the single-writer bottleneck across regions, requires explicit conflict resolution (last-write-wins, CRDTs, application merge logic).
  • Leaderless: no single point of write failure, consistency tuned via quorum size (W + R > N) rather than topology.
  • The real design question isn't 'how many leaders' — it's 'what happens when two writes to the same record briefly disagree.'
  • Cross-region multi-leader and leaderless designs both need clock or version-based conflict resolution — physical timestamps alone are an unreliable ordering signal across nodes.

Remember this

The three replication topologies are three different answers to the same question — what happens when two writes to the same data briefly disagree — not three tiers of one ladder.

Choosing a Sharding Key

A sharding key decides which shard owns each row, and it is the single hardest-to-reverse decision in a sharded system — resharding an entire production dataset to a new key is a project measured in weeks, not a config change. The key needs three properties together: even distribution (no single value should own a disproportionate share of the data or traffic), query alignment (most queries should be answerable from one shard, not a scatter-gather across all of them), and stability (a row's key should rarely need to change, since that means moving it between shards).

A plausible-looking key can still fail in production: sharding a multi-tenant SaaS product by tenant_id looks even in a demo with equal-sized tenants, and then one enterprise customer's usage grows to dwarf every other tenant combined — that single tenant's shard now carries a wildly disproportionate load, the exact hot-partition failure Hot Partitions and Hotspot Mitigation traces in depth. Test candidate keys against your actual data's distribution and your actual query patterns before committing, not against a demo dataset with uniformly-sized entities.

A key that looks even in a demo can still produce one dominant shard
A key that looks even in a demo can still produce one dominant shard

Quick reference

  • Even distribution: measure against your actual data's skew, not a uniform synthetic dataset.
  • Query alignment: a key that forces most queries to scatter-gather across every shard defeats sharding's purpose.
  • Stability: a key that changes for a row (a tenant upgrading plans, a user changing region) means migrating that row across shards.
  • Resharding to a new key is one of the most expensive operations in a running system — model growth before committing, not after a hot shard appears.
  • A composite or reserved-capacity key (isolating known outliers) is often more robust in practice than a single 'obviously even' field.
Sharding by tenant_id — looks even until one tenant dominates
1function shardForTenant(tenantId: number, shardCount: number) {2  return tenantId % shardCount;3}4// Fine when every tenant is roughly the same size.5// Breaks when tenant 4471 alone generates 40% of total write volume —6// that modulo puts all of it on one shard, permanently.
Composite key isolates a disproportionate tenant
1function shardForTenant(tenantId: number, isHighVolume: boolean, shardCount: number) {2  if (isHighVolume) {3    // Dedicated shard(s) reserved for tenants whose volume alone would skew a shared shard4    return DEDICATED_SHARD_ID;5  }6  return tenantId % (shardCount - RESERVED_SHARDS);7}8// Verify: seed with your actual tenant-size distribution, not a uniform demo dataset,9// before trusting a key's evenness.

Remember this

A sharding key needs even distribution, query alignment, and stability together — test it against your real data's skew, because a key that looks even in a demo can still produce a hot shard the moment one real entity outgrows the rest.

How the Three Combine in One Real System

Start from what you've actually measured, in this order: if one table's scans are slow, partition it — no new failure domain, no routing layer. If read capacity or availability is the limit, add replicas to whatever you have, sharded or not. If total write throughput or storage genuinely exceeds one well-partitioned, well-replicated database, shard — and only then does the sharding-key decision above become unavoidable.

A mature large-scale system typically looks like: data sharded across N databases by a carefully chosen key, each shard's largest tables partitioned by date or another natural range, and each shard replicated (leader-follower being the common default) for failover and read scaling. None of the three replaces the other two — they stack, each solving the specific bottleneck it targets.

Cheapest and most reversible first: partition → replicate → shard
Cheapest and most reversible first: partition → replicate → shard

Quick reference

  • Order of adoption by cost: partition → replicate → shard — cheapest and most reversible first.
  • A sharded system without internal partitioning just moves the 'one huge table' problem onto N databases instead of one.
  • A sharded system without replication has N single points of failure instead of one.
  • Re-evaluate the sharding key before scaling shard count further — redistributing data across more shards is exactly as expensive as the original resharding.
  • Model your growth curve, not just today's traffic, before choosing a sharding key — the cost of being wrong compounds with scale.

Remember this

Partition first for scan performance, replicate for availability and read capacity, and shard only when write throughput or storage genuinely exceeds one database — in a mature system, all three stack rather than substitute for each other.

Key takeaway

Partitioning, sharding, and replication answer three different questions — how to split a table, how to split a dataset across databases, and how to duplicate data for availability — and a real production system runs all three together rather than choosing one. The costliest decision among them is the sharding key: it needs even distribution, query alignment, and stability tested against your actual data, because resharding later is one of the most expensive operations a running system can undergo.

Practice (30 min): design a sharding key for a multi-tenant SaaS dataset where tenant size varies by two orders of magnitude. Model the distribution tenant_id % shard_count would produce against that real skew, and show it produces a disproportionately loaded shard. Redesign the key to isolate high-volume tenants, and verify the redesigned distribution is even across a representative sample of your actual tenant sizes. Pass when you can name, for your own system, which of the three axes each of your current bottlenecks actually sits on.

Share:

Related Articles

A shopping cart write to cart-77 needs to land on enough replicas that a later read is guaranteed to see it — but "enoug

Read

A user changes their display name, refreshes the page a second later from a phone on a different network, and sees the o

Read

A multi-tenant analytics platform partitions incoming events by tenant_id, hashed onto 16 shards — a design that looked

Read

Keep learning

Follow a structured path or browse all courses to go deeper.