KatInterview

Build a production spam filter for email

Machine LearningModel answer
HardModel answerMachine Learningml-system-designclassificationproduction-ml

Last updated

Design a complete ML system to classify incoming email as spam or legitimate, covering labeling, features, models, serving, metrics, and adversarial defenses.

You are building a spam detection system for an email platform serving hundreds of millions of users.

Design the complete machine learning pipeline to classify incoming messages as spam or legitimate mail. Your design should address:

  • Problem framing and labels: How do you define spam? Where do training labels come from, and what biases do they carry?
  • Data and features: What signals and feature families will you use? How do you extract them reliably?
  • Model architecture: What modeling approach fits the latency, scale, and accuracy requirements? Should you use rules, classical ML, deep learning, or a combination?
  • Inference and serving: How do you deploy models to handle peak traffic with strict latency budgets? How do you avoid training-serving skew?
  • Thresholds and decisions: How do you choose operating points? What actions (reject, quarantine, spam folder, inbox) map to which score ranges?
  • Metrics: What offline and online metrics matter? How do you validate that the system works before and after launch?
  • Adversarial robustness: Spammers adapt. How do you defend against evasion, poisoning, and probing?
  • Monitoring and iteration: How do you detect drift, retrain models, and roll out updates safely?

State your assumptions about scale, latency targets, and the relative cost of false positives versus false negatives. A strong answer balances technical depth with pragmatic trade-offs.

Hints

Hint 1

Consider that a false positive (legitimate mail marked spam) is far more damaging than a false negative. How does this asymmetry shape threshold choices and evaluation?

Hint 2

Spammers constantly evolve tactics. What normalization and robustness techniques prevent simple obfuscation attacks, and how do you monitor for new evasion patterns?

Hint 3

The system sits in the critical delivery path. How do you layer models of different complexity to meet latency requirements while maintaining high accuracy?