Archprimer
TradeoffAdvanced 8 min read

Replication vs Sharding

Replication copies data for high availability and read scaling; sharding splits data across nodes for write scaling. They solve different problems and are often combined.

databasescalingreplicationsharding

By Ratish Jain · Updated

Diagram with 5 components: App, Primary, Replica, Shard A, Shard B. Connections: App → Primary (writes); Primary → Replica (stream); App → Shard A (route); App → Shard B (route).
ServiceDatabase
Copies of the whole dataset versus splitting it into partitions.

The Decision

These are not really rivals — they scale different dimensions. Replication keeps full copies of the same dataset on multiple nodes. It buys high availability (a replica takes over on failure) and read scaling (spread reads across copies), but every node still holds all the data and all writes ultimately go through the primary.

Sharding splits the dataset horizontally by a key across nodes, so each shard holds only a slice. This scales writes and storage beyond one machine, but adds routing, rebalancing and cross-shard query pain.

So it depends on your bottleneck: reads and availability point to replication, write/storage volume points to sharding — and large systems usually do both, replicating each shard.

Side by Side

ReplicationSharding
What it doesCopies full datasetSplits dataset by key
Primary goalHA + read scalingWrite + storage scaling
Data per nodeEntire datasetOne partition only
Write scalingLimited by primaryScales across shards
Failure impactReplica takes overOne shard's data affected
ComplexityLag, failover, consistencyRouting, rebalancing, cross-shard joins
Query reachAny node has all dataCross-shard queries costly

Sharding Strengths & Weaknesses

Pros
  • Scales writes and total storage beyond a single machine
  • Failures are isolated to one shard's key range
  • Smaller per-node datasets keep indexes and working sets fast
Cons
  • Cross-shard joins, aggregations and transactions are hard
  • Choosing a shard key wrong causes hotspots and skew
  • Rebalancing and resharding are operationally painful

Decision Guide

Decision Guide

Reach for replication first when reads dominate or you need high availability and failover — it is simpler and often enough. Add sharding only when a single primary can no longer absorb the write throughput or the dataset outgrows one machine. Large-scale systems combine them: shard the data, then replicate each shard for redundancy and read fan-out.

Real-World Examples

MySQL read replicas
Classic replication for read-heavy web apps
MongoDB
Sharded clusters where each shard is a replica set
Cassandra
Partitions by hash and replicates via replication factor
Instagram
Sharded PostgreSQL to scale writes across many nodes

Interview Questions

Why doesn't replication solve a write-throughput bottleneck?

In leader-based replication all writes funnel through the primary and are then copied to replicas, so replicas add read capacity but the write ceiling stays fixed at one node — that requires sharding.

What makes shard-key selection so important?

The key determines data and load distribution; a poor choice (e.g. sharding by a low-cardinality or monotonically increasing field) creates hotspots where one shard gets most traffic, defeating the purpose. Consistent hashing helps spread and rebalance keys.

60-Second Revision
  • →Replication = full copies; scales reads and gives HA.
  • →Sharding = split by key; scales writes and storage.
  • →Replication's write ceiling stays at the primary.
  • →Sharding adds routing, hotspots, and cross-shard query cost.
  • →Big systems shard first, then replicate each shard.

Related

Everything on Archprimer is connected — follow the graph.