Part V — Blockchain & Trustless Consensus · Chapter 6

Sharding in blockchains

Hook

Every validator checking every transaction is safe, but it caps throughput at whatever one validator can process. What if the network split into groups, each handling only its own slice of accounts — and what breaks the moment a transaction touches two slices at once?

Intuition
bob0.0erin0.0alice1.0carol1.0dave1.0frank2.0
alice → bob crosses shard 1 → shard 0 (cross-shard). alice → carol stays inside shard 1 (same-shard).

Each shard validates its own accounts independently — that's where the parallelism (and the throughput gain) comes from. But alice → bob needs both shards to agree on the outcome, since neither shard alone holds both balances.

Accounts are grouped into shards by hashing their id — the same deterministic assignment every node computes independently, no coordination needed. Most transactions, like alice → carol, never leave their shard. The interesting case is alice → bob: two different shards each hold half the picture, and neither one alone can tell if the whole transaction is valid.

Formalize
  1. Every account is deterministically assigned to a shard

    shard(id)=toyHash(id)modN\text{shard}(\text{id}) = \text{toyHash}(\text{id}) \bmod N for NN shards — the same rule run independently by every node, so nobody has to broadcast "which shard is this account in."

  2. Most transactions stay inside one shard

    A transaction from account aa to account bb is same-shard if shard(a)=shard(b)\text{shard}(a) = \text{shard}(b), and cross-shard otherwise. Same-shard transactions are cheap: one shard has both balances and can validate the whole thing alone.

  3. Throughput scales with shard count

    throughput(N)=N×tpsper shard\text{throughput}(N) = N \times \text{tps}_{\text{per shard}} — this is sharding's entire payoff: shards process their own transactions in parallel, so total capacity grows with NN instead of staying fixed.

  4. Cross-shard transactions need a relay

    A cross-shard transaction can't be validated by either shard alone — it needs a receipt relayed from the source shard to the destination shard (and typically an acknowledgment back), costing extra messages that a same-shard transaction never pays.

  • NN — the number of shards; more shards means more parallelism, but also more transactions that cross a boundary.
  • relayHops — the extra messages a cross-shard transaction needs beyond a single shard's own validation.
Play
bob0.0erin0.0alice1.0carol1.0dave1.0frank2.0
Click an account to pick where the transaction starts.

Throughput with 3 shards at 10 tx/s each: 30 tx/s total — but every cross-shard transaction costs extra relay messages that a same-shard one never needs.

Click any two accounts to build a transaction between them and watch whether it settles in one message or needs a relay. The accounts don't move — sharding is a property of where an account already lives, not something a transaction can opt out of.

Worked example

6 accounts, 3 shards: shard(alice)=1, shard(bob)=0, shard(carol)=1, shard(dave)=1, shard(erin)=0, shard(frank)=2.

  1. Group the accounts by shard
    • Shard 0: {bob,erin}\{\texttt{bob}, \texttt{erin}\}
    • Shard 1: {alice,carol,dave}\{\texttt{alice}, \texttt{carol}, \texttt{dave}\}
    • Shard 2: {frank}\{\texttt{frank}\}
  2. A same-shard transaction: alice → carol

    Both land in shard 1, so isCrossShard=false\text{isCrossShard} = \text{false} — one message settles it.

  3. A cross-shard transaction: alice → bob

    Shard 1 vs shard 0 — isCrossShard=true\text{isCrossShard} = \text{true}. With 2 relay hops, the total message cost is 1+2=31 + 2 = 3, versus 1 for the same-shard case.

  4. Throughput at 10 tx/s per shard

    throughput(3)=3×10=30\text{throughput}(3) = 3 \times 10 = 30 tx/s total — triple a single validator group's capacity, as long as most transactions stay inside their own shard.

Checkpoint

Click through pairs of accounts to find every pair that lands in the same shard — 4 of the 15 possible pairs qualify. Cross-shard pairs are the common case; same-shard collisions are the rare, interesting one.

bob0.0erin0.0alice1.0carol1.0dave1.0frank2.0
0 of 4 same-shard pairs found
Click an account to start
Summary
shard(id)=toyHash(id)modN,throughput(N)=N×tpsper shard\text{shard}(\text{id}) = \text{toyHash}(\text{id}) \bmod N, \qquad \text{throughput}(N) = N \times \text{tps}_{\text{per shard}}

Sharding trades a single, easy-to-reason-about ledger for NN parallel ones — multiplying throughput, but introducing transactions that no single shard can validate alone. The next chapter steps back from scaling to security: what stops someone from just creating a flood of fake identities to control a fraction of the network for free?