KatInterview

Building a Low-Latency Email Abuse Filter with ML

Machine LearningModel answer
HardModel answerMachine Learningml-system-designspam-detectioncalibration

Last updated

Design a production ML pipeline that scores inbound mail within a tight latency budget, keeps hard-block false positives very low, and stays robust as attackers adapt.

You are asked to design a machine-learning system that classifies inbound email as unwanted or legitimate, and to take an enforcement action on each message before delivery.

Requirements

  • Synchronous scoring with p99 latency under 50 ms.
  • Hard blocks must reach precision of at least 98%. Wrongly blocking a password reset or an invoice is much worse than letting a promotional message through. Recall should still be as high as possible.
  • Senders are adversarial and change tactics within hours or days.
  • Possible actions: block, quarantine, tag/move to spam folder, deliver.

Cover the following in your answer

  1. Framing and labels: ham vs. spam, how to treat graymail (bulk mail the user signed up for), noisy or weak labels, and abuse reports that arrive late.
  2. Features: text n-grams, sender/domain/IP reputation, URL signals, MIME structure, lightweight embeddings, and how you prevent leakage (future information, reply and forward chains).
  3. Model and serving: compare logistic regression, gradient-boosted trees and a compact transformer; explain calibration and how you choose thresholds for each action.
  4. Training pipeline: sampling to cope with class prevalence, retraining cadence, and drift detection (stability metrics, canaries).
  5. Evaluation: offline metrics (PR-AUC, calibrated precision and recall at business thresholds) and online evaluation (A/B design, guardrails, holdouts).
  6. Feedback and safety: appeals, human review, bias, privacy and PII handling.
  7. Cost, reliability and rollback.

Finish by naming the three failure modes you worry about most and a concrete mitigation for each.

Hints

Hint 1

Start by stating assumptions (traffic volume, spam prevalence after network-level filtering, a per-stage latency budget). Then separate the problem into a cheap early gate, a main model, and an expensive model used only on uncertain messages.

Hint 2

Most leakage and evaluation mistakes come from time: compute features as of receive time, wait for labels to mature before training, split by time, and keep campaigns or sender clusters together in one split.

Hint 3

Thresholds should come from a calibrated model on unsampled recent data, using a confidence bound on precision for hard blocks. Treat thresholds as configuration so you can change or roll them back without redeploying the model.