Skip to content
tezvyn:

Design a Real-Time Anomaly Detection System for E-commerce Events

Source: aws.amazon.comHardHow cards are made

Design a Real-Time Anomaly Detection System for E-commerce Events

This tests your ability to design a real-time data pipeline and apply ML to a business problem. Outline a streaming architecture (e.g., Kinesis), processing, and storage.

What's really being asked

This question evaluates your ability to design an end-to-end, real-time system that solves a specific business problem. It's not just about naming technologies. The interviewer is testing if you understand the core challenge: defining an 'anomaly' in a system with natural, cyclical variance (seasonality). A senior answer moves beyond simple rules to a more robust, data-driven approach, demonstrating an understanding of both data engineering and applied ML.

The full answer

First, an ingestion and streaming layer. Events from the e-commerce application are sent to a scalable streaming platform like Amazon Kinesis Data Streams, which can handle high-volume, unordered events in near real-time.

Second, a transformation and storage strategy. An AWS Lambda function can be triggered by the Kinesis stream to perform lightweight transformations (e.g., parsing, enriching with timestamps). From there, Kinesis Data Firehose batches the data and reliably stores it in an Amazon S3 bucket. This S3 bucket acts as the data lake, providing the historical data needed for model training.

Third, the anomaly detection algorithm. Explicitly state that simple static thresholds are wrong. A drop of 50% at 3 AM might be normal, while a 20% drop at 3 PM is a critical incident. The solution is to use a model that understands seasonality. You can propose a managed service like Amazon Lookout for Metrics, which automatically learns from the historical data in S3 to establish a baseline for any given time and day, then detects significant deviations from it.

Fourth, an alerting and feedback mechanism. When Lookout for Metrics detects an anomaly, it should trigger an Amazon SNS topic. This topic can then fan out notifications to different destinations based on severity: a high-severity alert might go to PagerDuty for the on-call engineer, while a low-severity one posts to a team's Slack channel. The system should also allow engineers to provide feedback on alerts to improve model accuracy over time.

The mistakes people make

Proposing a naive, static threshold algorithm. For example, "alert if the count in a 5-minute window is 20% below the average of the last hour." This is the biggest red flag, as it completely ignores diurnal and weekly traffic patterns and would lead to an unmanageable number of false positives.

Designing a batch-processing system (e.g., a nightly Spark job). The requirement is for real-time detection to catch outages as they happen, not hours later.

Focusing only on one technology without connecting it to the overall architecture. For instance, only talking about Kafka without mentioning how data gets processed, stored, and analyzed.

What usually comes next

How much historical data do you need to train the initial model? (Answer: At least several weeks to capture weekly patterns; several months is better to capture monthly trends.)

What if you can't use a managed service like Lookout for Metrics? How would you build it? (Answer: Mention time-series forecasting models like SARIMA or Prophet, which are designed to handle seasonality, and run them on a compute platform like AWS Fargate or a scheduled Lambda.)

How do you handle a cold start for a new feature with no historical data? (Answer: Start with conservative static thresholds and a human-in-the-loop, collecting data to train a proper model as soon as a baseline is established.)

A concrete example

During Black Friday week, 'add to cart' events might average 50,000 per minute at 2 PM. On a normal Tuesday, the 2 PM average is 8,000. A static threshold would fail completely. An ML model trained on historical data knows to expect 50k events. If the count suddenly drops to 35,000 (a 30% drop), it correctly flags this as a high-severity anomaly. Conversely, if traffic at 4 AM is normally 200 events/minute, a drop to 100 is not a crisis and might not even be flagged, avoiding a false positive that would wake an engineer.

Interview question

For a real-time e-commerce anomaly detection system, what is the most robust method for identifying a significant drop in orders?

  • a.Using a batch job to compare the total daily order count against the monthly average at the end of each day.
  • b.Alerting when order volume in a 5-minute window falls 20% below the average of the preceding hour.
  • c.Monitoring the data ingestion pipeline for a sudden drop in the number of incoming records per second.
  • d.Comparing current order volume to a dynamic baseline learned from historical data for the same time of day and day of week.Correct
Why?

The most robust method accounts for natural seasonality in traffic. A dynamic baseline (D) does this, whereas a simple moving average (B) ignores daily/weekly cycles and would cause many false alerts.

Just read this? Test yourself on what you have been reading.

Read the original → aws.amazon.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on system design — each one lists the topics its interview covers.

See open roles