4.4.27 · D1Databases

Foundations — Distributed databases — sharding strategies, replication

2,125 words10 min readBack to topic

Before we can talk about sharding or quorums, we have to earn every symbol the parent note throws at you. We build them bottom-up: nothing appears here until the thing it rests on has already been drawn.


0. The stage: nodes, rows, and a table

Figure — Distributed databases — sharding strategies, replication

Look at the figure: one table on the left, three empty node-boxes on the right. The entire topic is about the arrows that connect them — which arrow a row takes (sharding) and how many boxes end up holding the same row (replication).


1. The counting symbols

Everything numeric in the parent note is built from four letters. We define each one on the picture before we ever put it in a formula.

Recall Which is which?

::: the total number of boxes (shards or replicas) ::: how many replicas a write must reach ::: how many replicas a read must query ::: the shard-key value of one row (the input to "which shard?")


2. The tool mod — remainder after dividing

The parent note's very first sharding rule is written hash(k) mod N, and it never explains mod. We fix that here — before we ever use it in that rule — because a 12-year-old has met division but maybe not this notation.

Figure — Distributed databases — sharding strategies, replication

The figure shows the number being dropped down the funnel of "divide by , keep the remainder." Watch it land in the amber bucket labelled 2 — that highlighted bucket is the shard the row goes to. The five boxes underneath are literally the possible remainders ; every conceivable input, no matter how large, is forced into one of them. That is the whole reason mod is the right tool for "which of shards?".


3. The tool hash — scramble to spread evenly


4. The picture of "spread": uniform vs hotspot

Figure — Distributed databases — sharding strategies, replication

The left panel shows what a good hash buys you: roughly equal bar heights across boxes — balanced load, no single box drowning. The right panel is a hotspot: range/sequential keys pile onto the last box. This single contrast is why the parent note prefers hashing, and it is also the seed of Load Balancing.


5. Fractions and the symbol — and where they come from

The parent note lives on fractions like and the wavy equals sign . Here we not only read them, we derive why those exact expressions measure how much data must move when you grow from to shards.

Recall Fraction sanity check

at ::: — the good case (consistent hashing), one arc moves at ::: — the bad case (naive mod), almost everything moves


6. Sets and the overlap idea (for quorums)

Quorum math () rests on one geometric fact about sets.

Figure — Distributed databases — sharding strategies, replication

7. The two verbs, side by side


Prerequisite map

Node = a box with data

Row and Table

Counting symbols N W R k

mod = remainder into N buckets

Hash = scramble to spread

Sharding = which box owns a row

Uniform load vs Hotspot

Fractions and approx equals

Resharding cost 1 over N plus 1

Sets and forced overlap

Quorum rule W plus R over N

Distributed Databases topic

This map feeds directly into the parent topic.


Equipment checklist

Self-test: can you answer each before reading the topic proper?

What does return, and how many possible values?
The remainder of ; exactly values, through .
Why hash a key before taking mod N?
Hashing destroys the ordering/clumping of raw keys so mod N spreads them evenly and avoids hotspots.
What do , , and count in quorum context?
= total replicas, = replicas a write must reach, = replicas a read must query.
Why is naive resharding cost ?
A key stays only if it lands back in its one old slot out of (chance ), so the fraction that moves is .
Why is consistent-hashing resharding cost ?
The new node steals only its single arc, which is of the ring.
When must two subsets of an -set share an element?
When their sizes sum past , i.e. (pigeonhole).
In one line, sharding vs replication?
Sharding splits distinct rows across boxes (scale); replication copies the same rows onto many boxes (survival).
Evaluate and .
and — same key, different box, which is why changing reshuffles data.