Skip to content
About
Main content

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.

Try each one before you open the answer.
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 .

Design

(lowercasing, ), ranking with 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 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 , 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

: about 0.5 s, so 2 queries per second per machine, and about 250 machines.

Design

plus codes (about 96 bytes per vector, about 0.96 GB in total) or , tuned from a measured curve of 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 .

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 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 , 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 , 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 , with forward and reverse copies.

Estimate

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, ) use an immutable built per run, with bulk synchronous processing and .

Trade-offs

The reverse copy doubles storage, and sampling hubs makes results approximate.

Read moreTraversal as a query primitiveDegree skew

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; 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.

Read morePregel / BSPPageRank and connected components

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 ). 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 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 (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

; 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 plus sum, count, min and max at each level. Use and XOR compression (for example 1 TB down to about 94 GB) and .

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 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 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, , 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