The interview problem

Practice prompt

Build an offline deduplication pipeline for ten million product images before training a classifier. Images include resized copies, crops, burst photographs and visually similar but different products. Prevent train/test contamination without deleting legitimate rare examples. Show how you would measure leakage and audit false merges.

Original ML-design practice, not a reported company interview. Counts and results are hypothetical. Primary research retrieved September 27, 2026; interview date not applicable.

1. Define the generalization unit

First decide what the evaluation should test: unseen images, unseen capture sessions or unseen products. Two different photographs of the same product may not be duplicates, but they must share a split when testing generalization to unseen products. Maintain separate relations for byte equality, visual duplicate evidence and shared product/session identity.

Do not interpret semantic similarity as identity. Two shoes with different sizes or defects can look almost identical while requiring different labels. A crop may remove the defect that determines the class. A duplicate policy must state which transformations preserve the task label and when a reviewer must resolve uncertainty.

Keep raw records and provenance immutable. Deduplication produces an inclusion and split manifest, not destructive deletion. Record original source, capture identity when known, preprocessing version, candidate matches and decisions. Conflicting labels on the same image are a data-quality issue requiring resolution, not a vote automatically won by the most copied label.

2. Separate retrieval from identity decisions

immutable images + provenance
             ↓
byte hashes + canonical decode hashes + visual embeddings
             ↓
 candidate retrieval → task-specific pair verification
             ↓
 reviewed grouping constraints + source/session relations
             ↓
  versioned family manifest → group-aware split assignment
             ↓
       cross-split audit → frozen training/evaluation release

Byte hashes cheaply identify exact files. Canonical decoded-pixel hashes can find lossless encoding variants that decode to the same pixels; lossy re-encoding usually needs perceptual matching, but the normalization policy must preserve meaningful information such as orientation and color. Perceptual hashes and embedding retrieval propose transformed-image candidates. A verifier uses image evidence and provenance to distinguish copies from lookalikes.

Measure candidate recall separately from verifier precision. A verifier cannot recover pairs never retrieved. Use known transformed pairs, manually reviewed difficult cases and a sampled exhaustive comparison on a manageable subset. Synthetic transformations test selected failure modes, not the full distribution of real duplicates.

All-pairs comparison for ten million records requires N(N−1)/2=49,999,995,000,000 pairs. Retrieving twenty neighbors per image creates up to 200 million directed candidates before reciprocal deduplication. That reduces work, but top-twenty retrieval may miss large duplicate families. Use multiple retrieval signals and inspect saturated neighbor lists.

3. Control graph chaining

Suppose A resembles B and B resembles C, but A and C depict different products. Taking connected components of noisy pair predictions merges all three. One false bridge can join thousands of records. Similarity above a threshold is not a transitive identity relation.

Distinguish conservative split-containment groups from removal groups. A suspicious bridge may justify keeping two families in the same split while still retaining both images for training. Actually dropping a record requires stronger evidence that it is redundant under the task. Large components, conflicting labels, mixed source identities and weak bridge edges enter review.

Candidate family checks can compare members with representative anchors and enforce task-specific cannot-link constraints. These are safeguards, not proofs of correctness. Preserve the evidence graph so an overturned edge can regenerate affected groups and split assignments. Version the resulting manifest and invalidate derived datasets when grouping changes. After a holdout is frozen, quarantine a newly discovered cross-split bridge rather than silently moving its test members into training. Resolve training exclusions and benchmark versioning explicitly.

4. Allocate families before augmentation

For a newly constructed dataset, assign whole accepted generalization groups to train, validation or test with a stable policy. Augmentation occurs only after assignment: a crop of a training image remains training data. Balance class and source coverage approximately without breaking a family to obtain exact row percentages. Large groups can make exact quotas impossible.

Consider six files: A and its crop A′, B and its re-encoding B′, plus unique C and D. A row split puts A, B, C, D in train and A′, B′ in test. Both test rows are contaminated: 2/2=100%. A family split can keep A/A′ and C in train, B/B′ in validation and D in test. It eliminates this known cross-split overlap but leaves only one test item, demonstrating the need for more independent data rather than pretending a tiny clean test is sufficient.

For an established external benchmark, do not silently reassign its test images into training. Exclude identified training-side relatives, document the benchmark policy and retrain when necessary. If prior model selection already used a contaminated test, cleaning files does not undo that knowledge; obtain a fresh holdout for a credible final comparison. Pretrained-model exposure may remain unknown and must be reported separately.

5. Quantify leakage without inventing improvement

Define test contamination as the fraction of test images with at least one accepted training-relative, with family-level counts reported alongside it. Suppose a 1,000-image test has 100 contaminated images. A model gets 98/100 contaminated examples and 720/900 remaining examples correct. Overall accuracy is 818/1000=81.8%, while the noncontaminated slice is 80%. The 1.8-point difference is a descriptive mixture effect, not a causal estimate of how much deduplication would change a retrained model.

Removing test images changes the evaluation population. Report the original result, contamination evidence and the explicitly defined clean slice; do not compare a new model's clean score against the old model's original score as a model gain. For new releases, evaluate both models on the same independently constructed holdout.

Audit false merges and false splits separately. A random sample of accepted pairs estimates pair precision under its sampling design, but does not prove whole clusters are correct. Review component-level errors and difficult negative pairs. Thresholds selected on held-out duplicate annotations should not be repeatedly tuned against final classifier test outcomes.

6. Budget and operate the pipeline

Ten million 512-dimensional float16 embeddings occupy 10,000,000×512×2=10.24 billion bytes, or 10.24 GB in decimal units, before the ANN index, identifiers and replicas. Retaining 200 million candidate records at an illustrative 24 bytes each adds 4.8 GB before storage overhead. Raw images and verifier computation can dominate these metadata costs.

If 50,000 uncertain pairs need thirty seconds of review each, effort is 1.5 million seconds, about 416.7 hours. Ten reviewers at five productive hours/day need about 8.33 working days, excluding adjudication. Review prioritization should emphasize harmful bridges and rare classes, but estimate aggregate quality using a separately designed sample.

New ingest must be checked against all protected holdout families, not just the newest training shard. Freeze the dedup model, thresholds and manifest for reproducibility. Monitor changes in source mix and transformations; rerun candidate-recall audits when they change. Keep rollback manifests so an overaggressive removal policy can be corrected without redownloading lost records.

7. Failure analysis and self-review

For a similarity score where larger means more alike, an overly high acceptance threshold misses crops and preserves leakage. An overly low threshold can erase rare products or collapse distinct labels. Distance-based scores reverse this threshold direction. Overgrouping reduces effective dataset diversity and distorts splits; undergrouping inflates apparent generalization. Provenance and task semantics constrain the visual model rather than merely decorating its score.

Follow-ups: Does zero detected overlap prove no leakage? No; detection recall is limited. Must every split-containment member be removed? No. Can byte hashing find resized copies? Generally not. Does cleaning a test set erase prior selection bias? No.

Score 0–2 each for the generalization unit, candidate-versus-verifier evaluation, graph-chaining controls, group-aware split policy and honest metric comparisons. A strong solution prevents contamination while preserving an auditable account of what changed.

Sources and next steps

Architecture, examples and arithmetic are original. For serving-time matching rather than dataset splitting, see near-duplicate detection.

Continue your preparation

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