AlgoViz

Scaling search and indexing

hard 28 min

How a search cluster grows: the right number and size of shards, replicas for reads and safety, safe placement, storage tiers for old data, rebuilding without downtime, and rules for scaling up and down.

See it run

Grow a cluster step by step, with the number behind each step.

Operations

Grow a cluster

From one node to a cluster with copies, tiers and a schedule.

Step 1 of 8

One node

Our systemSearchesCoordinatorNode 1200 GB
Disk
80%

One shard, one machine

All data in one shard, 200 GB. Every search reads it alone.

Step 1: One node

size  = docs * bytes * (1 + growth)P     = ceil(size / target)          # primariesC     = ceil(qps * cpu / cores)      # copies of eachplace(P * C, rules=[copies_apart, disk_under_85])roll_over(at="50 GB or 7 days")move_down(hot, warm, cold)scale(before_peak=True)
Helps
Data, reads, safety
Costs
Machines

Name the limit before each step: size, safety, reads, money.

In the real world

The same scaling search and indexing doing real jobs. Pick one and step through it.

One index a day for each of twenty teams, five shards each.

Step 1 of 4

After a day

AfterShardsEach
1 day10050 MB

100 shards

20 teams x 5 shards.

Step 1: After a day

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Primaries for concurrency

    critical

    Every search asks every primary, so each search gets more expensive.

    Wrong
    P = max(size / target, concurrency / 5)
    Right
    P = ceil(size / target)copies = ceil(qps * cpu / cores)
  • Copies apart as a score

    critical

    A penalty can be outweighed. Two copies then share a node.

    Wrong
    score -= 100 if has_copy else 0
    Right
    nodes = [n for n in nodes if not has_copy(n)]
  • Comparing shard numbers only

    major

    Shard 0 of another index is no copy of this shard 0.

    Wrong
    [c for c in copies if c.shard == shard]
    Right
    [c for c in copies if (c.index, c.shard) == (index, shard)]
  • Force merge on a live index

    major

    It makes huge segments, and later deletes stay in them.

    Wrong
    force_merge("today")
    Right
    roll_over("today")force_merge("yesterday")

Interview tips

  • How to explain it

    • Primaries: data and writes.
    • Replicas: reads and safety.
    • Nodes: room for both.
  • Memory trick: SCALE

    • Sharding, Copies.
    • Autoscale, Lifecycle.
    • Evaluate.
  • Numbers to say

    • 10 to 50 GB a shard.
    • 85, 90, 95% disk.
    • 30 GB in 5 minutes.
  • Watch out

    • Tiny shards.
    • Scaling in the peak.
    • Last replica removed at night.