No history yet

Interview Framework

A Framework for ML System Design

Machine learning system design interviews are different from algorithm challenges. They aren't about finding the most clever model. Instead, they test your ability to architect a practical, scalable system that solves a real business problem. It's about engineering, not just science. Success requires a structured way of thinking.

The goal of ML system design interview is NOT to measure your deep and detailed knowledge of different ML algorithms, but your ability to zoom out and design a production-level ML system that can be deployed as a service within a company's ML infrastructure.

A reliable framework helps you navigate the ambiguity of an open-ended prompt and ensure you cover all the critical components. Let's walk through a seven-step process that provides that structure.

1. Understand the Goal

Every design starts with a question. The interviewer might ask you to design a news feed, a recommendation engine, or a fraud detection system. Your first job is to clarify the ambiguity. Don't jump into solutions. Ask questions to translate the vague business goal into a concrete machine learning objective.

For a "news feed," is the goal to maximize user engagement (likes, comments, shares), time spent on the platform, or ad revenue? Each goal points to a different ML problem. For engagement, you might frame it as a prediction or ranking problem. For ad revenue, it might be a mix of ranking and predicting click-through rates.

Next, define the system's requirements and constraints. Who are the users? What's the expected scale? This is where back-of-the-envelope estimations come in. You need to estimate key numbers like Queries Per Second (QPS), daily active users, data storage needs, and acceptable latency for a response. These estimates will guide your architectural choices later.

MetricExample QuestionWhy it Matters
Queries Per Second (QPS)How many requests will the system handle at peak?Informs choices for server capacity and load balancing.
LatencyHow fast must the user get a response?A 100ms vs. a 2s requirement dramatically changes model and infrastructure options.
StorageHow much data will we collect and store per day?Determines the choice of databases and data warehousing solutions.
Training FrequencyHow often does the model need to be updated?Influences the design of the training pipeline (batch vs. online).

2. Design the Data Pipeline

With a clear goal, you need data to achieve it. Where does this data come from? What does it look like? You'll need to outline the data pipeline, which is the system for collecting, moving, and processing data for your model.

Consider data sources: user interaction logs (clicks, views), explicit feedback (ratings, reviews), and user or item metadata. Then, think about how to transform this raw data into useful signals for the model. This process is called feature engineering.

For a production system, you'll need a robust way to manage these signals. This is where a becomes essential. It's a centralized repository for storing, retrieving, and managing ML features. This prevents teams from re-creating the same features and ensures consistency between training and serving.

3. Select and Train the Model

Only now do you choose a model. In an interview, the specific algorithm is often less important than your justification for choosing it. The best practice is almost always to start with a simple, interpretable baseline model. For a classification task, this might be logistic regression. For a ranking task, it could be a simple scoring function based on a few key features.

A simple baseline is fast to train, easy to debug, and gives you a benchmark to measure more complex models against. Once you have a working baseline, you can then discuss iterating with more advanced models, like Gradient Boosted Trees or neural networks, and explain the trade-offs. More complexity might bring higher accuracy, but it often comes at the cost of increased training time, higher serving latency, and reduced interpretability.

Model selection in an ML system design interview is less about naming the most advanced algorithm and more about justifying why a particular approach makes sense given the problem, data, and constraints.

You also need to describe the training process. Will the model be trained offline in batches (e.g., once a day)? Or does it need to learn from new data in near real-time (online training)? Your choice here depends on how quickly the data patterns change and how fresh the model needs to be.

4. Design the Serving Infrastructure

Once you have a trained model, how do you use it to make predictions for users? This is the serving part of the system. A common pattern is to deploy the model as a microservice with an API endpoint. The application sends a request with the necessary features (e.g., user ID, item IDs), and the model service returns a prediction or a ranked list.

You should be able to sketch out this high-level architecture. Distinguish between the training pipeline and the serving pipeline. The training pipeline is often a batch process that runs periodically, while the serving pipeline needs to be a low-latency, high-availability service.

Lesson image

For complex systems like a news feed, a single model may not be enough. You might propose a architecture. The first stage (candidate generation) quickly selects a few hundred relevant items from millions of possibilities using a simple model. Subsequent stages use more complex models to re-rank this smaller set, balancing relevance and computational cost. This iterative approach, starting with a simple design and adding complexity where needed, is a hallmark of strong system design.

5. Evaluate and Monitor the System

How do you know if your system is working? You need a solid evaluation strategy that covers both offline and online metrics.

Offline evaluation happens before deployment. You hold out a test set of data and measure the model's performance using metrics relevant to the task, like NDCG for ranking or AUC for classification. This tells you if your new model is better than the old one on historical data.

Online evaluation is the true test. This involves deploying the model to a small fraction of users and measuring its impact on actual business metrics. The gold standard for this is an A/B test where you compare the new model's performance against the existing one (or a control group). Key metrics here would be the business goals you defined in step 1: user engagement, click-through rate, revenue, etc.

Once deployed, the system isn't done. You need to design a monitoring and alerting system. What happens if the model starts making bad predictions? You should monitor data distributions, feature values, and model prediction scores to detect drift or anomalies. If the input data changes significantly from what the model was trained on, it's time to retrain.

6. Iterate and Improve

A good system design interview doesn't end with a single, final architecture. It involves discussing the path forward. How would you improve the system over the next 6 months? This is your chance to discuss more advanced ideas.

You could talk about:

  • Adding more features: Incorporating real-time features, like what a user has just clicked on, can significantly improve model performance.
  • Trying more complex models: Now that the infrastructure is in place, you can experiment with larger neural networks or ensemble methods.
  • Personalization: How can you make the model user-aware? This could involve creating user embeddings or segmenting users into different groups.

By laying out an iterative roadmap, you show the interviewer that you think about ML systems not as static projects, but as evolving products that continuously improve.

7. Address Edge Cases and Failures

Finally, a production-ready system must be robust. What happens when things go wrong? Consider potential failure modes and how you'd handle them.

What if the feature generation service goes down? The system should have a fallback—perhaps to a simpler model that uses fewer features or even a non-ML-based heuristic. What about the "cold start" problem? For new users or new items with no interaction history, the model won't have any data. You'll need a strategy to handle this, such as defaulting to showing popular items.

Thinking through these edge cases demonstrates maturity and an understanding of what it takes to run a real-world ML service.

Quiz Questions 1/6

In an ML system design interview, what is the most critical first step after being given a prompt like "design a news feed"?

Quiz Questions 2/6

Why is it recommended to start with a simple baseline model (like logistic regression) instead of a complex one?

This seven-step framework provides a robust structure for any ML system design question. It forces you to think like an engineer, balancing trade-offs and focusing on the practical details of building and maintaining a system at scale.