The interview problem

Practice prompt

Design visual inspection for a production line making 100,000 metal housings per day. About 0.2% have actionable surface defects. Four cameras inspect each part before a diverter, and inspectors can review at most 600 parts per day. Detect rare and previously unseen defects without overwhelming review or silently passing parts whose images are missing.

Original ML-design practice, not a reported company interview. Production rates, defect prevalence and operating points are hypothetical. Primary references retrieved September 27, 2026.

1. Define defects and the physical decision

Agree on observable defects, minimum relevant size, acceptable cosmetic variation and severity with manufacturing quality engineers. Surface images cannot establish hidden structural integrity. Keep inspections requiring other sensors in the acceptance process. Define the unit of evaluation as a physical part, with all four views and one final disposition.

The output is pass, divert for inspection, or acquisition failure. A high anomaly score is evidence of visual difference, not proof of a harmful defect. Initially send flagged parts to review instead of automatically scrapping them. A missing view, wrong SKU, blurred image or uncertain part association must enter an explicit hold policy rather than becoming a low anomaly score.

Assume the line runs 16 hours/day and averages 1.736 parts/second. A part reaches the diverter two seconds after triggering its first image. Set a tested end-to-end decision deadline with margin for controller and actuator delay; average model inference latency is insufficient. Agree what happens when the hold buffer fills: slow or stop intake under the approved line policy, not silently change the acceptance threshold.

2. Build a part-centered inspection pipeline

part sensor + conveyor position → durable part token
four triggered cameras → image quality / SKU / view checks
                         → aligned crops → defect models → part-level policy
                         → controller command → diverter acknowledgment
images + versioned result → review station → adjudicated labels → offline evaluation

Bind each image to a part token, camera, trigger sequence and acquisition time. Conveyor tracking associates the decision with the physical part at the diverter. Detect missing or duplicate triggers and disagreement between sensor counts and image counts. A perfect classifier attached to the wrong part is a failed system.

Run inference at the line edge to avoid dependence on WAN latency. Cache a signed, validated model bundle and its matching preprocessing and thresholds. Record controller acknowledgments and reconcile failed diversion separately from prediction correctness. A network dashboard can update asynchronously; the local control loop must continue its documented fallback behavior when the dashboard is unavailable.

Use a bounded queue with deadlines. Do not increase batch waiting time to improve throughput if that causes early parts to miss the diverter. Profile image capture, transfer, preprocessing, inference, policy and actuation together under burst load and hardware degradation.

3. Combine known-defect learning with novelty detection

Start with deterministic imaging controls and geometry checks. Stable illumination, exposure and alignment can reduce variation more reliably than increasing model complexity. Preserve enough resolution for the smallest relevant defect; resizing a full image can erase a narrow scratch. Tiled inference increases compute and needs overlap rules so defects on tile boundaries are not lost.

For known defects with adequate labels, train a detector or segmentation model, with severity-aware part-level aggregation. For scarce or unknown defect types, learn normal appearance from verified good parts, for example through patch features and a normal-reference distance model. Select the reference set across legitimate material, finish and supplier variation. Contaminated “normal” examples can teach the model to accept defects.

Combine model outputs using a calibrated part-level policy. A maximum anomaly score across views can catch a small local issue but can also amplify nuisance alerts as the number of views grows. Do not average away a critical scratch visible in only one camera. Validate the complete four-view aggregation, not only each image classifier independently.

Maintain models or conditioning by SKU when shape differences are substantial. A new SKU is an onboarding event with imaging and acceptance validation. Unknown SKU detection should route to hold, not select whichever existing model produces the lowest score.

4. Collect evidence without leakage

Keep all views of a part in the same split. Separate production batches and later time periods so neighboring nearly identical parts do not make validation artificially easy. Hold out an entire camera installation or production line when evaluating transfer; keep every view of its parts out of training rather than splitting views of the same part across datasets. Include normal process variation, tiny defects and difficult lighting in the evaluation, with clear severity definitions.

Collect expert labels at part level and localization masks for selected cases. Adjudicate ambiguous marks using the actual quality specification. Use confirmed defect examples to tune sensitivity, but estimate false-diversion workload on a representative stream of good parts. An enriched defect test set cannot directly provide production precision.

Audit a random sample of passed parts as well as flagged parts. Otherwise the feedback loop observes false alarms but hides misses. Track sampling probabilities and delayed downstream discoveries. Synthetic scratches can stress the pipeline or supplement training, but they do not establish performance on real unseen defects.

5. Choose a threshold with a review budget

At the stated prevalence, a day contains approximately 200 defective and 99,800 good parts. Suppose operating point A detects 95% of defective parts and falsely flags 0.5% of good parts. Expected counts are 190 true flags, 10 misses and 499 false flags: 689 reviews/day, exceeding capacity by 89. Flag precision is 190/689 ≈ 27.58%.

Suppose operating point B detects 90% of defective parts and falsely flags 0.2% of good parts. Expected counts are 180 true flags, 20 misses and 199.6 false flags, or 379.6 reviews/day. Precision is about 47.42%. Fractional counts are expectations across days, not literal partial parts.

Operating pointExpected reviews/dayExpected missed defects/dayWithin 600 review slots?
A: 95% recall, 0.5% false-positive rate68910No
B: 90% recall, 0.2% false-positive rate379.620Yes, before other holds

Capacity alone does not make B acceptable. If quality requires an expected rate of at most ten model-missed actionable defects/day at this volume and prevalence, B fails. At 95% recall, satisfying 600 model-flag reviews would require false-positive rate at most (600 − 190)/99,800 ≈ 0.4108%, assuming no other review work. Whether the model can achieve that point must be measured; it is not a free threshold adjustment. These are model misses, not final escaped defects. If inspectors incorrectly release 2% of the 190 true flags at A, expected escapes become 10 + 0.02 × 190 = 13.8 before any downstream checks, even with perfect physical diversion. Measure reviewer errors and diversion failures separately. Expected counts are not a hard daily upper bound.

At two minutes per review, A requires about 22.97 staff-hours/day and B about 12.65. Six hundred slots correspond to 20 hours of direct review time. Missing-image holds, auditing passed parts, breaks and burst arrivals consume additional capacity. Reserve those budgets explicitly. If the quality target and review capacity cannot both be met, improve imaging/model discrimination, add review capacity or reduce line rate; do not hide the conflict.

6. Evaluate the action, not just the heatmap

Report part-level recall by defect severity and type, good-part false-diversion rate, missed defects per production volume, review yield and acquisition-failure rate. Include correct physical diversion and end-to-end deadline compliance. Pixel localization quality helps diagnose models but a large correctly segmented stain must not hide repeated misses of tiny critical cracks.

Use thresholds fixed on validation data and evaluate on untouched later batches. Confidence intervals should reflect batch dependence and the small number of real defects. Zero observed misses on a handful of defects is weak evidence. Anomaly-detection benchmarks are useful for method comparison; their category mix and capture conditions do not establish factory acceptance.

For a new defect type, assess held-out-type stress tests without claiming exhaustive coverage of future defects. Unknown visual changes can be harmless; unseen harmful changes can resemble normal material. Maintain downstream quality checks and an escalation process for newly discovered failure modes.

7. Size the image path and detect drift

Four views × 100,000 parts/day gives 400,000 images/day. At 2 MB compressed per image, raw-image storage is 800 GB/day, or 24 TB for 30 days before replication. At 16 operating hours/day, average input is 6.94 images/second. A worker sustaining 20 images/second appears sufficient on average, but four-camera trigger bursts, tiled inference and failover must be benchmarked. A nominal second worker is not redundancy unless either can meet the deadline during the other's outage.

Monitor focus, exposure, registration error, missing views, score distributions and review outcomes by camera, SKU, shift and material lot. A camera bump can create widespread high scores; a dirty lens can obscure defects while reducing meaningful evidence. Compare trusted reference captures after maintenance. Retrain or recalibrate only after root-cause investigation and evaluation; automatically normalizing a sudden production defect outbreak could conceal it.

Version model, normal-reference set, preprocessing, threshold policy and camera configuration together. Roll back that compatible bundle when needed. Keep part tokens and decision logs available for tracing affected production lots; retain images according to the agreed operational policy rather than assuming every image must remain forever.

8. Follow-ups and self-review

Follow-ups: Why can higher precision accompany more missed defects? Point B flags fewer good and defective parts, trading recall for workload. What changes with eight views? Reevaluate aggregate false flags, compute and part association; do not reuse a four-view threshold blindly. Why not train only on reviewed parts? That selection hides passed defects. What if the line cannot stop? Negotiate a physically feasible reject/hold path before promising safe online inspection.

Score 0–2 each for physical part association and deadlines, appropriate known/unknown defect modeling, leakage-resistant data collection, correct workload calculations, and handling drift and insufficient review capacity. A strong answer ties the model to the real acceptance and diversion process.

Sources and next steps

  • MVTec AD — primary industrial anomaly benchmark description with normal training images and pixel annotations.
  • MVTec AD 2 — primary benchmark description including changed lighting conditions and challenging inspection scenarios.

The factory architecture, thresholds, counts and operating policy are original practice. No dataset is downloaded or incorporated here, and benchmark performance is not claimed for this hypothetical line. Continue with precision–recall trade-offs.

Continue your preparation

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