The interview question

Find duplicate and near-duplicate listings in a marketplace.

Combine cheap candidate generation with careful verification, and keep similarity distinct from identity.

01. Define which duplicates matter

Exact file equality, copied text with small edits, and two legitimate sellers offering the same product are different cases. Establish whether the action is grouping, warning, review, or removal. A high similarity score should not silently become proof of policy violation.

Start with exact hashes for identical normalized content, then use approximate candidate generation for edited copies. Preserve original content and the normalization version so a surprising match can be explained and reproduced.

02. Use a cascade to reduce comparisons

Candidate retrieval
Pair verification
Review or grouping

For one million listings, comparing every unordered pair requires roughly 500 billion comparisons. Candidate generation narrows the work using category blocks, token signatures, or embedding neighbors. A more expensive verifier then compares candidate pairs using text, images, attributes, and temporal context.

Blocking improves efficiency but can permanently hide duplicates placed in different categories. Measure candidate recall separately from verifier accuracy. Include a secondary retrieval path for known ways that copied listings evade the primary block.

03. Work through a simple similarity

Suppose normalized title A has tokens {red, leather, chair} and title B has {red, leather, armchair}. Their Jaccard similarity is intersection size 2 divided by union size 4, or 0.5. This score ignores word order and cannot establish that chair and armchair are semantically related.

Character edits, synonyms, and reused product images need richer evidence. Tune thresholds on labeled pairs representing realistic hard cases, including legitimate lookalikes. Precision at the review budget is useful, but candidate recall determines which duplicates can ever be found.

04. Avoid unsafe transitive merging

If A resembles B and B resembles C, it does not follow that A and C are interchangeable. A chain of pairwise matches can create a large, incoherent cluster. Choose explicit cluster constraints, representative checks, or human review for consequential merges.

Updates and deletions must invalidate affected matches and preserve an audit trail. Follow-up: new listings arrive faster than the batch job. Add an online candidate lookup for recent items and reconcile with a periodic full pass. Track age-to-detection as well as final pairwise quality.

Practice the follow-up

Self-review

Construct three short titles where adjacent pairs look similar but merging all three would be misleading.

Connect this to similarity search.

Sources & further reading

scikit-learn: clustering methods and geometry. The interview scenario, calculations, and proposed design choices are illustrative.

Continue your preparation

Choose a connected learning path or browse more ML system design questions. Read our editorial method and attribution policy.