Scaling Search and Indexing 00:00:01 Split and replicate for different reasons A product catalogue occupies two hundred gigabytes on one shard. Search is slow, so the team orders more replicas. Before that purchase, ask whether the problem is the size of one index or the number of queries competing for it. All data in one shard, 200 GB. Every search reads it alone. Ten primaries of 20 GB, still on one node. Parallel work on its cores. Place a replica of each shard on a different node from its primary. For protection from a whole availability-zone loss, check the zone placement as well. Node 2 fails. Its primaries are replaced by their copies, then new copies are made on the others. Old indices move to cheaper machines. CPU was 85% at yesterday's peak. Copies are added an hour before today's. Splitting a growing index distributes bytes and parallelizes portions of a query. Replicating a shard gives independent searches another copy to use, at the cost of storage and update work. 00:01:04 Estimate the primary count 100 million documents of 2 KB, 50% growth. 100 million times 2 KB. Half as much again. By a target of 30 GB. 150 million over ten shards is 15 million each, far under 200 million. More primaries: each search asks more shards. Begin with source documents, then account for indexing overhead, merge activity and headroom. More primaries reduce individual shard size while increasing fan-out and coordination overhead for searches crossing the whole catalogue. 00:01:40 Choose copies from the real workload Eighteen hundred searches arrive each second. Each search uses twenty milliseconds of processor time on every shard it queries. 8 busy cores of 16. Ten shards, one copy on each machine. Each write is done on five copies. Each additional replica receives indexed changes. A read-heavy workload may justify the extra cost, but replicas on an already exhausted machine compete for the same compute and filesystem cache. 00:02:13 Rebuild a generation safely From 5 to 15 primaries, without a pause. All searches use the alias products. Fifteen primaries, no replicas, no refresh during the load. From a snapshot, throttled. Replicas on, replay the changes, run sample queries on both. One atomic step. Searches now use v2. Create the replacement index, backfill historical documents and catch up concurrent changes. Only switch the alias when the new generation's completeness and query behavior have been verified. 00:02:47 Small shards spend real resources One index a day for each of twenty teams, five shards each. 20 teams x 5 shards. 3,000 shards, 150 GB in all. 150 GB at 30 GB each. One shared index with a field for the team, and rollover by size. Many tiny shards can cost memory and scheduling even when actual documents are small. Consolidation can help if per-tenant isolation, access rules and future growth still remain manageable. 00:03:19 Put replicas where they can do work p99 is 300 ms, CPU is at 90%. No node is added. Copying costs CPU and disk. A third node takes copies. For a while copying is extra work. Three machines share the searches. Compare latency, errors and utilization before and after placing copies on independent capacity. Verify the surviving layout after a machine fails, not just the number of shard copies listed as assigned. Primaries distribute the indexed data, replicas copy it, and machines supply actual CPU, memory and disk channels. Changing the shard count on paper cannot create physical resources the cluster does not have.