LESSON 07 · Sharding and growth

Split hot and large indexes

Partition by observed load and replicate hot slices.

SYSTEM VIEW

The suggestion path

Diagram view
Reads—
s–z reads—
Shards asked—

Watch 5,600 reads a second spread over three prefix ranges, then see what replicas, a split and a spanning prefix each cost.

  1. Shard only when one machine can’t hold the index or replicas can’t absorb the reads: an 8 GB index may need only replicas of one full copy. Otherwise a prefix range map assigns terms to shards, and “sa” goes to Shard s–⁠z.

    8 GB index
    replicas may do
    Ranges
    a–i, j–r, s–z

    What changed

    • Range map: a–i, j–r, s–z
    • “sa” → Shard s–z
  2. Equal alphabet ranges are often unbalanced: common first letters draw more reads. Of an example 5,600 reads a second, s–⁠z gets 45%, 2,520 a second, and a–⁠i and j–⁠r 1,540 each. A node handles 1,000, so every shard is over, s–⁠z most.

    One node
    1,000/s
    s–z share
    45%

    What changed

    • 5,600 reads/s
    • s–z: 2,520/s, 45% of reads
    • a–i, j–r: 1,540/s each
  3. Three replicas for s–⁠z (840 a second each) and two each for a–⁠i and j–⁠r (770 each) keep every node under 1,000. If memory is fine, replicas fix the heat without touching the ranges. Measure bytes, request rate and CPU per range to choose.

    s–z
    3 replicas
    a–i, j–r
    2 replicas each

    What changed

    • s–z: 3 replicas, 840/s each
    • a–i, j–r: 2 replicas, 770/s each
    • Ranges unchanged
  4. When a range outgrows one node’s memory, split it: here s–⁠z becomes sa–⁠sm and sn–⁠sz. The routing map is versioned during the move, v1 to v2 in this example, so every read follows one consistent map. Under v2, “sa” goes to the new Shard sa–⁠sm.

    Map
    v1 → v2 (example)
    s–z
    sa–sm and sn–sz

    What changed

    • Shard sa–sm
    • Shard s–z → Shard sn–sz
    • Range map v1 → v2
  5. No one shard now holds every candidate for “s”, so the Query API asks both Shard sa–⁠sm and Shard sn–⁠sz and merges their top-K results, much as Elasticsearch merges across its shards. Both lists must come from the same ranking version, v812.

    “s” spans
    2 shards
    Ranking
    v812 on both

    What changed

    • “s” asked of 2 shards
    • 2 top 5 lists merged into 1
    • Both lists from v812
  6. A fanned-out read is as slow as its slowest shard, here Shard sn–⁠sz. Keeping a prefix’s descendants together avoids fanout but can concentrate storage and traffic; precomputed lists for very short prefixes, in a small separate table, avoid it where it’s broadest.

    Merge waits for
    the slowest shard
    Short prefixes
    own small table

    What changed

    • Shard sa–sm answers first
    • The merge waits for Shard sn–sz

Space plays · ← → step · Home resets

THE IDEA

How it works

Sharding splits an index across machines, and it is worth doing only when one machine cannot hold the index or replicas cannot absorb the reads. If the whole index is 8 GB, replicas of one full copy may be all you need. Otherwise, a prefix range map can assign terms to serving shards. Equal alphabet ranges are often unbalanced: common initial letters and one-letter prefixes may be much hotter than rare ones. Measure bytes, request rate, and CPU per range, then split busy ranges or add read replicas. Version the routing map during movement.

As an example, three shards cover a–i, j–r, and s–z, with s–z receiving 45% of 5,600 reads per second. That is 2,520 per second. If a node handles 1,000, s–z needs three replicas, while the other two shards at 1,540 each need two. If memory is fine, replicas fix this without touching the ranges.

If a requested prefix spans shards, the query tier must fetch candidates from each relevant shard and merge their top-K results, much as Elasticsearch merges results across its shards. The request is then as slow as the slowest shard. Keeping all descendants together avoids this fanout but can concentrate storage and traffic. Precomputing lists for very short prefixes in a small separate table also avoids fanout where it would be broadest. A merged response should not combine incompatible ranking versions.

DECISION POINT

The “s” shard is saturated while “x” is quiet. Name two remedies.

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Partition boundaries should reflect measured load, not equal letter counts.
  • Cross-shard prefixes need fanout and merge; replicas address read heat.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
DiagnoseQUESTION 01

A team gives each of 26 letters its own shard. Within a week the “s” shard is at 90% CPU and “x” is idle. Why?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.