How would you design a spam filter for a small college email server that receives emails a day, of which about are spam? If your model achieves recall and a 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
- Clarify scale, objective and metrics: emails/day ( spam, legitimate ham) is under emails/s, so one small server scores mail within seconds of arrival. Frame this as binary classification ( spam, 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.
- 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.
- Pick the model (start simple, then improve): start with a blocklist/allowlist plus multinomial naive Bayes or logistic regression—both train in seconds on 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.
- Serving architecture and daily error calculation: score each email on arrival and route scores above a chosen threshold to the spam folder. With spam and ham emails/day, recall and FPR give: (Precision is .)
- 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 daily false positives (perhaps to or ), at the cost of letting a few more of the missed spam emails into the inbox.
- 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
- Optimising overall accuracy on imbalanced data or treating false positives and false negatives as equally bad, when blocking an important email is much worse.
- Using random k-fold splitting across time, which leaks future spam campaigns into training.
- Letting the model block emails completely instead of sending borderline scores to a separate spam folder where users can recover them.
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 requests per second, and you log (kilobyte, bytes) per prediction (inputs, output and model version). How much storage does this take per day, per days and per year ( 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 users and movies? Using a rating table where Movie A has ratings , Movie B has and Movie C has from three users, what is the cosine similarity between Movie A and Movie B, and how much storage is needed to precompute recommendations per user nightly?