Scenarios
Longer problems, like those in senior system design interviews. A strong answer estimates with numbers first, names the mechanism, then recommends a fix and says what it costs.
1Product asks for search over 10 million listings stored in PostgreSQL. LIKE '%word%' takes 9 seconds. What do you do?Show the answer
Explain
A B-tree needs a fixed prefix; a leading wildcard has none, so every row is scanned.
Options
A full-text index inside the database (GIN) for a first version, or a dedicated search cluster with an inverted index.
Design
Analyzers (lowercasing, stemming), BM25 ranking with block-max skipping, and a second, case-preserving field for exact matches.
Costs
A larger index, a delay before new rows are searchable, and a rebuild whenever the analyzer changes.
Recommend
Start with GIN if the needs for ranking quality are modest; move out when facets and relevance tuning dominate.
Read moreThe one assumption behind every ordinary indexThe inverted indexAnalyzers and tokenizersScoring
2A results page with category facets is 40 times slower than the results alone. Diagnose and fix.Show the answer
Diagnose
Facets need counts over all matches, which defeats top-k skipping, and they need a forward copy of each field.
Fix
Compute exact counts only for fields with few distinct values; sample the matches and show "about N"; precompute aggregates for common filters; and avoid facets on fields with many distinct values, which do not merge across shards.
Trade-off
Approximate counts may be off in either direction, which is acceptable because they are only a guide.
Read moreFaceting defeats early terminationHigh-cardinality facets do not compose
3New listings take a minute to appear in search. After you cut the refresh interval to 100 ms, queries got slower. Explain and design.Show the answer
Explain
New data becomes visible at each flush. Each flush creates a segment, and every query pays a fixed cost per segment, so segments multiply and every reader pays.
Design
Keep a refresh of about 1 s, merge more aggressively to keep a handful of segments per shard, and consider a separate small real-time index for the newest items.
Failure mode
Under heavy writes, merge work can pile up.
Read moreSegments and near-real-time refreshThe merge debt of a text index
4Design 'similar items' over 10 million listings at 500 queries per second, with p99 latency under 100 ms.Show the answer
Estimate
Brute force reads 30 GB per query: about 0.5 s, so 2 queries per second per machine, and about 250 machines.
Design
IVF plus PQ codes (about 96 bytes per vector, about 0.96 GB in total) or HNSW, tuned from a measured curve of recall against throughput, using brute-force results on a sample as the truth (for example, target recall 0.95). Then rerank the survivors exactly.
Shard
Every shard may hold a neighbour, so every query goes to every shard, and tail latency is the maximum over shards.
Trade-offs
Recall below 1, failures that are silent, and memory.
Read moreThe arithmetic that forces everythingThe three ANN familiesOne distributed note
5'Similar items in Pune, in stock, under 500 rupees' returns 3 results instead of 10. Why, and what do you build?Show the answer
Explain
The filter selects about 0.5% of the corpus, in the hard middle band. Filtering after the search would need about 2,000 candidates to return 10 results.
Route by selectivity
If the filter leaves fewer than about 100,000 items, brute-force them (50,000 × 3 KB = 150 MB, about 3 ms at 50 GB/s). Otherwise use the approximate index with a large over-fetch, or a traversal that is aware of the filter.
Alternatives
Separate indexes per value for fields with few distinct values. State the recall you accept.
Read moreFiltered ANNEscapes with prices
6A data scientist wants to ship a better embedding model next week. How do you roll it out?Show the answer
Explain
The embedding model is a schema: old and new vectors live in different coordinate systems, so comparing them is meaningless.
Roll out
Build a second index over the full corpus, write new items to both for a period (for example two weeks), compare quality offline and with an A/B test, cut over, and delete the old index.
Costs
Double storage and a full re-embedding run. With no ground truth, reproducibility replaces correctness, so pin the model and index versions.
Read moreAn embedding model is a schemaWhat the approximation must respect
7Searching for the product code 'KT-4471' fails with vector search but works with keyword search. Natural-language queries show the opposite. What do you do?Show the answer
Design
Run both and combine them with reciprocal rank fusion, which uses ranks and ignores score values that cannot be compared.
Costs
Two systems, two round trips, a constant to tune, and A/B testing to validate quality.
Read moreHybrid search and rank fusion
8Design 'friends of friends who bought this' for 2 million users, some of them celebrity accounts with huge followings.Show the answer
Split by shape
A shallow query (2–3 hops) from one starting user is an OLTP workload: use mutable adjacency lists, with forward and reverse copies.
Estimate
With 100 connections each, hop 3 reaches about 1 million vertices before deduplication.
Handle hubs
Cap or sample the expansion of celebrity accounts, or precompute their purchaser sets, because a hub's cost depends on the data, not on the query.
Analytics
Deep or global analytics (PageRank, connected components) use an immutable CSR built per run, with bulk synchronous processing and vertex-cut partitioning.
Trade-offs
The reverse copy doubles storage, and sampling hubs makes results approximate.
9A bulk-synchronous graph job on 64 workers runs 5 times slower than the estimate based on average work. Diagnose.Show the answer
Diagnose
The cost of each round is set by the slowest worker. A hub vertex receives millions of messages, so its worker is the straggler in every round.
Fix
Vertex-cut partitioning; combiners that sum messages per destination; and fewer rounds (stop PageRank early, activate only vertices that changed).
Consider
Asynchronous execution, only if you accept non-determinism and harder recovery.
10Design courier matching within 500 m for a city, and reporting by delivery zone.Show the answer
Matching
Index locations by grid cell (for example H3). Cover the 500 m circle with cells, over-covering on purpose, then refine with an exact geodesic distance in metres.
Zones
Store each zone polygon with a bounding box and an inner box, to accept or reject most points cheaply. Zones that cross partitions are duplicated, so deduplicate by zone ID before summing.
Correctness
Enforce the coordinate system and geometry validity at write time, and fix one predicate (ST_Covers) for points on a boundary.
Cost
Depends on how well shapes fill their boxes, so test with real zones.
Read moreFilter-and-refineThe boundary problemDiscrete global gridsCoordinate reference systems
11Your metrics store runs out of memory after a label change, and old dashboards cannot answer p99 questions. What do you do?Show the answer
Estimate
60 series × 2 million users is 120 million series; at 3 KB each, about 360 GB.
Fix
Remove the label, add a quota at write time, and move per-user debugging to logs.
Make quantiles composable
Store t-digest sketches plus sum, count, min and max at each rollup level. Use delta-of-delta and XOR compression (for example 1 TB down to about 94 GB) and tiered retention.
Be honest
Data already rolled up without sketches can never answer p99. Emit explicit "offline" events so gaps can be interpreted.
Read moreSeries identity and the cardinality wallDownsampling and rollupsGorilla compressionGap filling
12Legal asks you to delete a user from everything, including the data used to train models. What breaks?Show the answer
The conflict
Immutable snapshots, retention policy and deletion conflict. The user must disappear from the inverted index, the vector index, rollups, graph projections and training snapshots. Some structures can only delete at rebuild, and some cannot delete without invalidating what they were fitted to.
Plan
Keep a deletion log and tombstone now; rebuild on a schedule, with the measured rebuild time as your deletion deadline; keep training datasets outside normal retention, but with an explicit expiry.
Be honest
Retraining is the only complete answer. This tension is unresolved.
Read moreEmbedding stalenessThings the usual taxonomy does not cover
13A product manager wants 'semantically similar, in stock, within 5 km, from the last 7 days' in one query. How do you respond?Show the answer
Explain
These structures do not combine: one answers, the rest are filters applied afterwards, and filtering afterwards degrades as selectivity falls.
Design
Estimate the selectivity of each condition. If the combined selectivity is very low, run the most selective structure first (often location or time) and brute-force the rest, or accept lower recall and measure it.
Measure separately
Recall against brute force, relevance against judged result sets, and the business outcome, because improving one does not guarantee the others.
Read moreMulti-stage retrievalFiltered ANN
14A team asks whether to adopt a new specialized engine for a new workload. Give a decision procedure.Show the answer
Can it stay general?
Can the predicate become a range or an equality? If yes, stay in the general engine.
Name it
If not, name the shape of the problem, the resource that binds and the knob that trades it.
Price the pipeline
A second write path, a freshness metric, reconciliation, a deletion path, and rebuild time as the recovery objective.
Check the alternative
Whether an extension of the general engine fits the budget, since that line moves every year.
Be honest
Say what you cannot verify, and who will notice first.
Read moreWhen to specialize at allThe recurring arithmeticSpecialized versus general engines