Scaling search and indexing
hard 28 minHow 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
- 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
| After | Shards | Each |
|---|---|---|
| 1 day | 100 | 50 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
criticalEvery search asks every primary, so each search gets more expensive.
WrongP = max(size / target, concurrency / 5)RightP = ceil(size / target)copies = ceil(qps * cpu / cores)Copies apart as a score
criticalA penalty can be outweighed. Two copies then share a node.
Wrongscore -= 100 if has_copy else 0Rightnodes = [n for n in nodes if not has_copy(n)]Comparing shard numbers only
majorShard 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
majorIt makes huge segments, and later deletes stay in them.
Wrongforce_merge("today")Rightroll_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.