RAG & Retrieval·Question 55 of 100Advanced

Your index will not fit on one machine. How do you shard it, and what breaks?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

First, push back on the premise, because it is usually wrong. Modern machines take a lot of RAM, and quantization buys an order of magnitude. Hundreds of millions of vectors on one large node, with product quantization plus a rerank pass on full-precision vectors, is very achievable. Sharding is a real operational tax, so I would exhaust vertical scaling and compression first. That said, when you genuinely need it:

Sharding strategy is the whole decision:

Full worked answer with diagram

First, push back on the premise, because it is usually wrong. Modern machines take a lot of RAM, and quantization buys an order of magnitude. Hundreds of millions of vectors on one large node, with product quantization plus a rerank pass on full-precision vectors, is very achievable. Sharding is a real operational tax, so I would exhaust vertical scaling and compression first. That said, when you genuinely need it:

Sharding strategy is the whole decision:

  • Random or hash sharding: even load, but every query must scatter to every shard. Simple, and the default.
  • Semantic sharding by cluster: only probe relevant shards, so less compute per query, but load skews badly and recall drops at cluster boundaries.
  • Attribute sharding by tenant, language or time: this is usually the right answer when it applies. A per-tenant shard turns the nastiest problem in filtered ANN, a highly selective filter over a graph index, into a small unfiltered search over one shard. Time-based shards let you skip old data for recency-filtered queries and drop cold shards to cheaper storage.

What breaks:

  • Top-k is not composable naively. You cannot ask each of 10 shards for top-10 and merge to a global top-10 correctly with an approximate index, because per-shard recall is not uniform. You over-fetch per shard, then merge, and over-fetching is the tax you pay for correctness.
  • Tail latency dominates. Scatter-gather means p99 of the query is p99 of the slowest shard, so with 20 shards you sample the tail 20 times per query. This is the thing that actually hurts, and the mitigations are hedged requests and shard-count discipline.
  • Skew. With tenant sharding, one enormous tenant lands on one shard. You need to split large tenants and pack small ones.
  • Rebalancing. Adding shards rehashes data. Consistent hashing helps; it is still a migration.
  • Recall becomes unmeasurable. You can no longer compare against exact search easily, so keep a sampled brute-force path for ground truth.

My default: shard by tenant if the workload is multi-tenant, otherwise by time, and only then by hash.

Worth sketching. The over-fetch numbers show why a global top-k across shards is not free, and the straggler arrow shows where p99 actually comes from.

flowchart TD
    Q["Query"] --> F["Scatter to<br/>every shard"]
    F --> S1["Shard 1:<br/>over-fetch top 50"]
    F --> S2["Shard 2:<br/>over-fetch top 50"]
    F --> S3["Shard N:<br/>over-fetch top 50"]
    S1 --> M["Merge and rerank<br/>to a global top 10"]
    S2 --> M
    S3 -->|"query p99 is the<br/>slowest shard p99"| H["Hedge the straggler"]
    H --> M

What a good answer covers

  • First, push back on the premise, because it is usually wrong
  • Modern machines take a lot of RAM, and quantization buys an order of magnitude
  • Hundreds of millions of vectors on one large node, with product quantization plus a rerank pass on…
  • Sharding is a real operational tax, so I would exhaust vertical scaling and compression first
  • Random or hash sharding: even load, but every query must scatter to every shard

Key terms: Random or hash sharding · Semantic sharding · Attribute sharding · What breaks · Top-k is not composable naively · Tail latency dominates · Skew · Rebalancing · Recall becomes unmeasurable

Interviewer follow-ups to expect

  1. With 20 shards and a scatter-gather query, how do you keep p99 from being dominated by the slowest shard?

  2. How much do you over-fetch per shard, and how would you determine that number?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep