The interview prompt

“Design a spam-detection system for a messaging product.”

First clarify what the service can inspect. Server-side content classification assumes the service legitimately has access to message content. In an end-to-end encrypted product, that assumption changes and the design may rely on metadata, user reports, or an explicitly specified on-device component.

For this scenario, assume authorized server-side text processing, 20 million messages per day, and a 100 ms p95 classification budget. The system can allow, quarantine, or send a message for review. These are illustrative requirements.

01. Define spam and the cost of mistakes

Separate unsolicited commercial spam from phishing, harassment, and other policy categories when their labels and actions differ. Define annotation guidelines and preserve a version of the policy used to label each example.

False positives can hide an important legitimate message. Evaluate the quarantine policy at a strict precision target chosen with product owners, while tracking spam exposure and recall. A single accuracy figure does not capture the trade-off.

Offer a recoverable action and an appeal path where appropriate. Permanent deletion is a different product decision from placing a message in a reviewable folder.

02. Build labels with provenance

Combine reviewed samples, user corrections, and carefully interpreted reports. Reports are signals rather than unquestionable ground truth: they can be mistaken, coordinated, or reflect personal preference.

Sample messages outside the flagged set so evaluation is not limited to what the old detector already found. Use time-based validation and group near-duplicate campaign content when testing generalization to new campaigns.

Fit text preprocessing only on training data. Record what normalization removes; punctuation, character patterns, and URLs may contain useful signals. Handle multilingual and very short messages as distinct cohorts.

03. Use a cascade with bounded cost

Message assessment
Authorized inputFast rules + modelOptional deep scorerAction + reason
Escalate selected uncertain cases only when the extra stage fits the latency and review budgets.

Start with a sparse text model, such as multinomial naive Bayes on count features or logistic regression on a validated text representation. Naive Bayes makes conditional-independence assumptions yet can be a useful fast baseline; its probability outputs still need validation. See the scikit-learn guide.

Add sender history and rate features only when permitted and available at decision time. For difficult cases, evaluate a richer text model behind the fast stage. Preserve rule, feature, and model versions for debugging.

04. Evaluate the policy people experience

Measure precision and recall for each action and category, appeal reversals, quarantine recovery, review workload, and decision latency. Evaluate language and sender-tenure cohorts; a model may mistake unfamiliar legitimate communication for spam.

Use a reviewed holdout and temporal campaign tests. Keep a baseline for comparison and inspect false positives directly. A small aggregate gain is not persuasive if it hides a severe regression for a meaningful cohort.

Shadow deployments reveal score and latency changes without changing delivery, but they cannot fully measure the effects of a different user-facing policy. Follow with a controlled release where appropriate.

05. Plan for adversarial change

Monitor missing features, report patterns, score distributions, and mature reviewed outcomes. New campaigns may shift content quickly, but an alert is a reason to investigate rather than automatically train on every report.

Use temporary rules with owners and expiry dates for confirmed incidents. Keep review queues bounded and reserve a path for high-impact false positives. Avoid exposing detailed internal detection features in user-facing explanations that do not require them.

Connected fundamental

Distinguish drift from a broken pipeline ↗

Choose the response that matches the evidence.

06. Defend the design

“Reports spike after a product change.”

Check UI changes, report incentives, and logging before concluding that spam prevalence rose. Compare independently reviewed samples.

“The model is unavailable.”

Use a documented limited fallback, such as established rules and recoverable quarantine for selected cases. Monitor the impact and restore normal processing promptly.

Common mistakes

Assuming access to encrypted content, trusting every report, testing only on known campaigns, or using irreversible actions for uncertain predictions.

Sources & further reading

scikit-learn: naive Bayes provides background on fast text-classification baselines. The system and policies here are illustrative design choices.

Continue your preparation

Choose a connected learning path or browse more ML system design questions. Read our editorial method and attribution policy.