Sharding and Replication
Sharding and replication are the two foundational approaches to building distributed data systems. They solve different problems β but most production systems combine them.
Single Instance β The Starting Point
Everything happens on one node. Strong consistency, simple reasoning, but no horizontal scalability. Examples: single-instance Postgres, Redis without clustering, monolithic app servers.

Vertical scaling β a bigger CPU, more memory, more disk β is the only move left, and it ends. Past a point the next machine size does not exist, or it costs more than a second node would. The thing you keep, and cannot get back from any of the diagrams below, is that one node has a single order of writes and nothing to fail over to.
Replication
Single-leader replication
The simplest replication setup: one leader (a.k.a. primary, master, write replica) accepts all writes. Followers (read replicas, hot standbys) receive a stream of changes from the leader and serve reads.

Every follower holds a full copy, so the only routing rule is βwrites go to the leader.β The leader ships changes as a write-ahead log or as logical commands. That buys read capacity. It does not buy write capacity: every mutation still lands on one node, and a write-heavy workload stays blocked on that node no matter how many followers you add.
Examples: Postgres streaming replication, MySQL master-slave, MongoDB replica sets, Redis Sentinel.
Multi-leader replication
Multiple nodes accept writes simultaneously. Each leader replicates to others; each leader can also have its own followers.

Each leader is a follower of the other leaders, and usually keeps followers of its own. How changes move between leaders is its own trade-off: all-to-all (simple, chatty, fine for a handful of leaders), circular (less bandwidth, higher latency, a break in the ring stalls propagation), or star (one coordinator, which is simpler and is also a bottleneck). Prefer this over leaderless replication when each region should have a real leader, when writes already split cleanly across leaders, or when you want conflicts resolved by a known policy instead of at read time.
When you need it:
- Geographic distribution. Each region has a local leader for low-latency writes.
- Collaborative editing. Mobile devices that can be offline for days are essentially leaders that sync.
- High write availability. No single write bottleneck.
The cost: conflict resolution. When the same data is written at two leaders concurrently, you must decide whose change wins.
Multi-leader systems generally cannot guarantee linearizability. Google Spanner uses atomic clocks (TrueTime) to approximate it, but thatβs specialized hardware and serious operational complexity.
Leaderless replication
Every node accepts both reads and writes. No special coordinator. Used by Cassandra, DynamoDB, Riak.

This is multi-leader taken to the end: every node is a leader, so there is no role to fail over and no node whose log is βtheβ order. Clients (or a coordinator the client picks at random) have to run the quorum. Conflicts are not settled when the write arrives. They are discovered on read, when the responses disagree, which makes the read path heavier than in a leader system.
Quorum consistency. With N replicas, if you read from R replicas and write to W replicas where R + W > N, youβre guaranteed to read the latest value.
N = 3 replicas
W = 2 (write to 2)
R = 2 (read from 2)
W + R = 4 > N = 3 β guaranteed consistent reads
Sharding
Sharding (also called horizontal partitioning) splits data across nodes. Each node holds only a slice. Writes scale horizontally because different shards can accept writes in parallel.

Sharding does not imply replication. A shard can be one node, or it can be its own single-leader, multi-leader, or leaderless group. The question the placement strategy does not answer is how a request finds its shard. A directory (MongoDBβs mongos, Citus) looks it up and becomes a dependency. A smart client computes the shard from the key and skips that hop, which only works when the function is deterministic and every client knows it. Or any node accepts the call and forwards it (Cassandraβs coordinator), which needs no special router and costs an extra hop whenever the client guessed wrong.
Sharding strategies
The hot-spot problem
A single popular key (a celebrity user, a viral product) can overwhelm one shard. Mitigations:
- Salting keys β append random suffix to spread writes across shards.
- Read replicas of hot shards β let reads scale even if writes are concentrated.
- Caching layer β most hot data should never reach the database.
Resharding
Adding or removing shards is operationally expensive. Strategies:
- Pre-split shards β start with more shards than you need, redistribute as you grow.
- Logical shards over physical β many logical shards on fewer physical nodes; rebalance by moving logical shards.
- Online migration tools β Vitess for MySQL, Citus for Postgres handle this with minimal downtime.
Combining Sharding and Replication
Most production systems use both:

You now operate two failure domains: a shard can be wrong or unreachable, and a replica inside it can too. Storage multiplies by the replication factor times the shard count, and so does the runbook. MongoDBβs usual shape is a replica set per shard. Kafkaβs is the same idea with different names: a partition is the shard, and each partition has a leader plus followers. The combination is worth it when one machine cannot hold the data or the write rate. It is not worth it for a dataset that still fits, because you pay the complexity before you need the scale.
- Each shard is replicated for fault tolerance and read scaling.
- Different shards live on different nodes for write scaling.
Shard A (users a-h) Shard B (users i-p) Shard C (users q-z)
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Leader A β ββreplicationββΊβ Leader B β β Leader C β
β Follower A1 β β Follower B1 β β Follower C1 β
β Follower A2 β β Follower B2 β β Follower C2 β
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
Each shard is independent. A query for user βkβ routes to Shard B; cross-shard queries (e.g., βgive me all usersβ) fan out to all shards.
Multi-Tenant SaaS Patterns
For multi-tenant SaaS, shard-by-tenant is often the right model:
Recap
- Replication = same data on multiple nodes (availability + read scaling).
- Sharding = different data on different nodes (write scaling).
- Production systems combine them β each shard replicated for fault tolerance.
- Three replication models: single-leader (simple, scales reads), multi-leader (writes scale, conflicts), leaderless (symmetric, quorum-based).
- Sharding strategies: range-based, hash-based, directory-based, consistent hashing. Each has trade-offs.
- For multi-tenant SaaS, shard-by-tenant (with hybrids for big customers) is usually the right model.