A spam detection system decides whether an incoming message is unwanted or harmful before it reaches the user. It combines a machine learning model that scores each message using content, sender reputation, authentication results, and behavioral signals with a decision layer that turns that score into an action such as inbox, spam folder, or quarantine.
Imagine you're building an email service used by millions of people.
Every day, the system receives legitimate messages from friends, colleagues, banks, and businesses. But mixed into those messages are millions of unwanted emails. Some are harmless advertisements. Others contain suspicious links, impersonate trusted organizations, or attempt to steal sensitive information.
Your job is to decide which messages should reach the user's inbox and which should be filtered out. And you need to make that decision automatically, at massive scale, without accidentally hiding important emails.
This is the Spam Detection System Design problem.
It's a classic Machine Learning System Design interview question because it brings together almost every important aspect of production ML. We need to understand the product requirements, define the prediction problem, collect training data, engineer features, choose a model, evaluate its performance, and deploy it into a reliable, low-latency system.
But there's another challenge. Unlike ordinary classification problems, spam detection operates in an adversarial environment. The people generating spam are actively trying to defeat our models. So a solution that works today may become less effective tomorrow.
In this article, we'll walk through how an experienced Machine Learning Engineer would approach this problem in an actual interview.