The interview problem
Design duplicate-question suggestions for a technical forum with ten million questions and 100 queries per second. Return up to three likely duplicates, allow no match, and initially leave question closure to moderators. Explain how the system preserves version constraints, handles stale canonical answers and measures mistakes that could wrongly close a useful question.
Original ML-design practice, not a reported company interview. Workloads, platform examples and calculations are illustrative. Primary documentation retrieved September 27, 2026; publication dates unstated; interview date not applicable.
1. Define equivalence before choosing embeddings
Two questions are duplicates when they pose the same problem under compatible constraints, so an appropriate solution transfers between them. Sharing nouns, error messages or a broad topic is insufficient. Separate the labels equivalent, answer-covered, related, incompatible constraints and insufficient context.
Answer coverage can be directed: a broad troubleshooting guide might answer a narrow question, while the narrow answer does not cover the broad guide. Do not turn directed coverage edges into equivalence classes. Likewise, the existence of an accepted answer does not prove that answer remains correct.
| Question on an invented upload platform | Relationship to Q1 |
|---|---|
| Q1: Retry a timed-out upload without creating a second object, using version 2 with idempotency tokens. | Reference problem |
| Q2: Version 2 upload response was lost; how can I safely repeat the request with its original token? | Likely equivalent, subject to full context |
| Q3: Retry safely on version 1, where the server has no deduplication support. | Related, but the same token-based solution does not transfer |
| Q4: How can version 2 uploads finish faster? | Related vocabulary, different intent |
These capabilities are fictional, not claims about a real API. An unknown version is uncertainty, not a wildcard that makes every version compatible. Matching version numbers also does not establish equivalence by itself.
2. Retrieve broadly, then compare the actual problems
authorized query + original text and code
↓
explicit and inferred constraints
↓
lexical candidates ∪ dense candidates
↓
pairwise duplicate-task reranker
↓
compatibility checks + calibrated policy
↓
suggestions or abstention → moderator reviewUse lexical retrieval to preserve exact symbols, versions and error strings, and dense retrieval to find paraphrases. Deduplicate the candidate union by question ID. A cross-encoder can jointly inspect the query and each candidate after cheaper retrieval narrows the corpus. This is a useful architecture, not proof that an off-the-shelf relevance model understands duplicate-question policy.
Keep the original text alongside extracted constraints. Normalization that removes “without,” code operators or version suffixes can destroy the distinction the system must learn. Use hard exclusions for explicit, reliable incompatibilities; uncertain model-extracted metadata should not silently eliminate every candidate. Show the unresolved constraint or ask for clarification.
Apply authorization before exposing candidate snippets, and enforce it before any model stage that is not permitted to process the content. Recheck access before presenting a canonical target or recording a decision. Private questions must not leak through titles, explanations or cached matches.
3. Train on difficult distinctions
Train the pair model on the duplicate task with both question bodies, code context and important constraints. Include near-identical wording with different versions, mutually exclusive requirements, repeated errors with different causes and questions whose crucial detail appears late in a code block.
Moderator closure history is useful evidence but reflects historical policy, available canonical targets and human mistakes. Sample unclosed pairs and disagreements for adjudication. Record label rationale and uncertainty. When mining hard negatives, check whether a retrieved candidate is an unrecognized positive rather than automatically treating every unlinked pair as negative.
Split evaluation by duplicate family and time so paraphrases of the same underlying question do not appear on both sides of the split. Keep evaluation families out of model-training pairs, while allowing their historically available canonical questions in the retrieval corpus; otherwise the split could remove the very targets being tested. Construct each evaluation corpus as it existed at the query time. A future canonical answer must not make a historical query appear easier than it was.
Calibrate decision scores on data that resembles the serving candidate pool. A relevance score, cosine similarity or sigmoid output is not automatically a calibrated probability of equivalence. Reassess calibration when retrieval, corpus composition or moderation policy changes.
4. Separate equivalence from canonical selection
After identifying an equivalent problem, choose a usable target based on answer validity, applicable versions, moderation state, coverage and accessibility. The oldest or most-voted question is not necessarily the best destination. Equivalent questions can share a stale answer; that should trigger content review rather than a claim that the existing answer solves the current issue.
Record question and answer revisions, candidate-generation version, model version, policy threshold and moderator action. Reassess affected links after substantial edits, deletion or permission changes. Keep closure reversible and preserve the original discussion and decision evidence.
Do not apply transitive closure to uncertain predictions. If the model says A matches B and B matches C, A and C may still have incompatible constraints. Maintain pair evidence and validate cluster consistency before changing canonical groups. A connected component of embedding-neighbor links is not a reliable duplicate group.
5. Work through an end-to-end evaluation
Suppose an adjudicated held-out set has 1,000 queries. Exactly 300 have at least one valid equivalent target in the accessible corpus; 700 have none. A query can have multiple acceptable targets.
| Stage | Observed outcome | Metric |
|---|---|---|
| Candidate retrieval | Valid target retrieved for 270 of 300 positive queries | 90% query-level candidate coverage |
| Reranking | Valid target first for 240 of those 270 | 88.89% conditional top-one accuracy |
| Retrieval plus ranking | Valid target first for 240 of all 300 positive queries | 80% positive-query top-one accuracy |
| Decision policy | 200 single-target suggestions; 190 valid | 95% suggestion precision |
The policy’s valid-suggestion recall is 190/300 = 63.33%, and it suggests something on 200/1,000 = 20% of queries. For this example, assume all ten invalid suggestions occur on queries with no valid duplicate. Then the 800 abstentions contain 110 positive queries and 690 no-duplicate queries. The false-positive rate on no-duplicate queries is 10/700 = 1.43%, which differs from the 5% error fraction among suggestions. Without that assumption, precision alone cannot tell us the composition of abstentions: a positive query can receive the wrong target.
The reranker cannot recover the 30 positive queries whose candidate pool contains no valid target. Adding ground-truth positives to that pool creates a useful isolated reranker experiment, but hides retrieval failures. The Sentence Transformers evaluator documents an always_rerank_positives option that defaults to true. For a realistic pipeline test, provide the actual retrieved documents and disable that option. Keep oracle-candidate experiments labeled separately.
Measure precision across every returned suggestion when serving up to three targets; do not generalize the single-target example to a three-target product. Report candidate coverage, valid-suggestion recall, abstention, false positives on no-duplicate queries and constraint violations separately. Include version, language and question-length cohorts.
6. Match the threshold to the action
Consider a deliberately simplified automatic-closure decision with calibrated equivalence probability p. Let an incorrect closure cost 100 units and leaving a true duplicate unlinked cost 1. Assume correct actions cost zero and there is no review option:
expected cost of closing = 100(1 − p) expected cost of leaving = p close only if p > 100 / 101 ≈ 0.990099
This calculation illustrates asymmetric consequences, not a ready-made production threshold. Severity varies, calibration is imperfect and human review creates another action. A suggestion threshold can differ from an automatic-closure threshold because the moderator sees and can reject the proposal.
Launch as suggestions with concise supporting evidence: matching intent, relevant constraints and unresolved differences. Avoid explanations that invent guarantees absent from either question. Monitor moderator acceptance, reversals, appeals and time spent reviewing; clicks alone do not establish correct duplicate detection.
7. Estimate serving cost
Ten million 768-dimensional embeddings at two bytes per component require 15.36 GB of raw vector payload. Three copies require 46.08 GB before the approximate-nearest-neighbor index, text, metadata and operational overhead. Comparing every unordered corpus pair would involve about 50 trillion pairs, so online queries need bounded candidate retrieval.
At 100 queries/second and 100 candidates per query, reranking requires 10,000 pair evaluations/second. If a measured worker sustained 250 pairs/second for the chosen model and input lengths, that would require 40 fully utilized worker equivalents, or about 58 at a 70% utilization target. This hypothetical throughput is not a hardware benchmark or a latency guarantee.
Measure batch delay, queueing and long-input cost. Preserve critical version and code context rather than blindly truncating the part that distinguishes the questions. Bound the number of candidates and input size, and compare recall losses when reducing them.
Cache only with the relevant query, content, permission and index versions. Invalidate matches affected by canonical edits. If the reranker fails, abstain or show clearly labeled related results; do not present dense proximity as verified equivalence just because the expensive stage is unavailable.
8. Test changes that invalidate a match
- A new version changes the solution: reassess compatibility and target answer validity instead of preserving a link solely because the wording is unchanged.
- The canonical question becomes private: stop exposing it and its snippets; select another accessible target or return no suggestion.
- The original query is edited: invalidate decisions tied to the old revision and preserve the audit trail.
- A broad answer covers a narrow question: offer useful related coverage without automatically asserting symmetric equivalence.
- Moderators disagree: retain the rationale and uncertainty, refine policy and measure the disputed cohort rather than forcing noisy labels into ground truth.
- Indexing lags behind publication: count missing accessible positives as pipeline misses; do not blame only the reranker or inject the missing target during evaluation.
Interview follow-ups
- What if the question omits its version? Ask for the missing constraint or show uncertainty. Missing metadata is not evidence of compatibility.
- Can we close everything above 0.99 similarity? Similarity is not calibrated equivalence probability, and closure needs a separate loss and governance policy.
- Why keep lexical retrieval? Exact symbols, errors and version identifiers can distinguish cases that dense models place close together.
- Why evaluate no-match queries? A system forced to select a duplicate for every query can rank well on positive-only tests while making harmful suggestions in practice.
Self-review rubric
A strong answer defines context-dependent equivalence, supplies hard negative examples and separates candidate retrieval, pair scoring and action policy. It allows no match, states metric denominators and respects the retrieval ceiling. An excellent answer distinguishes directed answer coverage, versions canonical decisions, preserves permissions and avoids turning uncertain pair predictions into irreversible group merges.
Sources and attribution
- Sentence Transformers: Retrieve and Re-Rank — two-stage retrieval architecture.
- Sentence Transformers: Cross-encoder evaluation — evaluator candidate handling and positive-inclusion settings.
Page publication dates unstated; retrieved September 27, 2026. The forum scenario, equivalence examples, metrics and cost calculations are original practice material. No company interview attribution is claimed.
Continue your preparation
Choose a connected learning path or browse more ML system design questions. Read our editorial method and attribution policy.