KatInterview

Real-Time Anomaly Detection System for High-Traffic Platform

Machine LearningModel answer
HardModel answerMachine Learningml-systemsstreamingfeature-engineering

Last updated

Build a streaming anomaly detection architecture that processes millions of requests per second, handles extreme class imbalance, and maintains feature consistency.

You're building an anomaly detection system for a large-scale platform that needs to identify suspicious patterns in real-time across global traffic. The platform receives enormous request volume, but only a tiny fraction represents true anomalies—creating significant technical and ML challenges.

Context

Your platform processes 5 million requests per second worldwide. Suspicious patterns (credential stuffing, scraping bots, coordinated abuse) occur in roughly 0.01% of traffic. You need to:

  • Flag anomalies within 500ms of the request arriving
  • Route flagged events to a labeling system for model improvement
  • Maintain consistency between the features your model sees during inference and what your training pipeline uses

Your Task

Design the end-to-end ML system. Address:

  1. Architecture: Describe the data pipeline from request ingestion through model inference to action. How do you achieve sub-500ms latency at this scale?

  2. Feature computation: How do you build time-windowed aggregations (requests per IP per minute, velocity metrics, behavioral patterns) in a streaming environment? What happens when traffic is fragmented across regions?

  3. Labeling pipeline: With only 0.01% anomaly rate and perhaps 10,000–50,000 labels per day available from human reviewers, how do you decide which examples to label? How do you avoid wasting labels on redundant examples?

  4. Feature consistency: The features computed at inference time (with live streaming state) will differ from features recomputed hours later when labels arrive. How do you ensure your training data reflects exactly what the model saw?

Discuss trade-offs, failure modes, and where you'd compromise under cost or complexity constraints.

Hints

Hint 1

Consider a multi-stage inference pipeline where a cheap filter sees all traffic and an expensive model sees only flagged candidates

Hint 2

Partition your stream by entity (IP, user, device) so all events for one entity flow to the same worker—this makes windowed aggregations local

Hint 3

Log the actual feature vector at inference time rather than recomputing features later when labels arrive