How would you design a spam filter for a small college email server that receives 5,000 emails a day, of which about 20% are spam? If your model achieves 95% recall and a 0.5% false-positive rate, how many spam emails are missed and how many legitimate emails are wrongly flagged per day?

ML system design, Case studies
Level L2 Elementary. Length Medium. Nature Th+Mat Both.

What's being asked

Whether you can walk through a complete ML system design end to end on a small, realistic problem, including error trade-offs and a daily mistake calculation.

Key idea

Follow the standard ML design steps at small scale: prioritise high precision so real emails are not hidden, collect labels from 'mark as spam' clicks, start with simple text and sender features in a naive Bayes or logistic regression model, and verify daily false positives before tuning the decision threshold.

Steps

  1. Clarify scale, objective and metrics: 5,000 emails/day (1,000 spam, 4,000 legitimate ham) is under 0.1 emails/s, so one small server scores mail within seconds of arrival. Frame this as binary classification (y=1 spam, y=0 ham), prioritising high precision and low FPR (false-positive rate) offline so exam notices are not hidden, and tracking user 'not spam' rescues and spam reports online.
  2. Plan data, labels and simple features: start with a labelled seed set plus implicit user feedback (moves to spam = positive, rescues from spam = negative), watching for label delay and unseen false positives. Extract bag-of-words or TF-IDF (term frequency–inverse document frequency) counts, sender domain reputation, link counts, attachments and sender-authentication headers.
  3. Pick the model (start simple, then improve): start with a blocklist/allowlist plus multinomial naive Bayes or logistic regression—both train in seconds on 5,000 emails/day, output spam probabilities and show which words triggered a flag. Later, if spammers adapt, upgrade to gradient-boosted trees or a compact text transformer.
  4. Serving architecture and daily error calculation: score each email on arrival and route scores above a chosen threshold t to the spam folder. With 1,000 spam and 4,000 ham emails/day, 95% recall and 0.5% FPR give: Missed spam=1,000×(1−0.95)=50 emails/day,Legitimate emails flagged=4,000×0.005=20 emails/day. (Precision is 950/(950+20)≈97.9%.)
  5. Evaluation, launch and interviewer trade-offs: split training and validation by time (never random shuffle, so future spam patterns are not leaked), launch first in shadow mode or a soft 'possible spam' tag before auto-hiding mail. An interviewer will probe the threshold trade-off: raising the threshold cuts the 20 daily false positives (perhaps to 2 or 4), at the cost of letting a few more of the 50 missed spam emails into the inbox.
  6. Monitor and iterate: retrain weekly on recent user-labelled emails, alert on sudden spikes in spam-folder volume or user rescues, and update rules for new phishing templates. The large-scale spam-detection case study builds directly on this by adding distributed streaming, adversarial evasion and image/URL analysis.

Common mistakes

How long your answer should be

About 4 minutes; walk through the design stages cleanly and show the two daily counts.

Read this

Previous in ML system design: A model serves 1,000 requests per second, and you log 1 KB (kilobyte, 1,000 bytes) per prediction (inputs, output and model version). How much storage does this take per day, per 30 days and per year (365 days), why do we log predictions at all, and how can you cut the cost?
Next in ML system design: How would you design a movie recommendation system for a small app with 10,000 users and 2,000 movies? Using a 3×3 rating table where Movie A has ratings (3,4,0), Movie B has (4,3,0) and Movie C has (0,3,4) from three users, what is the cosine similarity between Movie A and Movie B, and how much storage is needed to precompute 20 recommendations per user nightly?