Model Serving: Turning Trained Models into Live APIs
Model serving wraps a trained machine learning model in an API, making it a live service that can generate predictions. It's how you power features like real-time fraud detection or product recommendations.
Why it exists
A trained machine learning model is just a static file. By itself, it cannot provide value to users or other systems. Model serving exists to operationalize this asset, wrapping it in a live, networked service that can accept data and return predictions on demand.
The mental model
Think of model serving as creating a specialized microservice for your ML model. You've trained a model to perform a task, like identifying cats in photos. Serving that model means packaging it inside a web server with an API endpoint. Other services can then send an image to /predict and get back a JSON response like {"is_cat": true, "confidence": 0.98}.
How it works
A model serving framework (like TensorFlow Serving, TorchServe, or a custom FastAPI app) loads the trained model file into memory. It then exposes an API (usually REST or gRPC) that accepts input data. When a request arrives, the server preprocesses the data, feeds it to the model for inference, post-processes the output, and returns the final prediction. This is a core part of MLOps, which focuses on making this process reliable and efficient in production.
When to use it
Use model serving whenever you need to integrate ML predictions into a production application, especially for real-time use cases. This is essential for features like personalized recommendations, dynamic pricing, content moderation, and fraud detection. It's the standard way to make a model usable by other services.
When not to use it
Model serving is often overkill for batch processing. If you only need to score a large, static dataset periodically (e.g., once a day), it's more efficient to run a simple batch inference script that loads the model, makes all predictions, and saves the results. A live API endpoint adds unnecessary complexity.
One canonical example
A credit card company wants to block fraudulent transactions. A data scientist trains a model on transaction data. This model is deployed via a serving platform. When a customer swipes their card, the transaction details are sent to the model's API. The model returns a fraud score in milliseconds. If the score is high, the transaction is automatically declined, preventing the fraud in real-time.
Interview question
Which scenario best illustrates the primary use case for model serving?
- a.Providing immediate fraud risk scores for credit card transactions as they occur.Correct
- b.Running a daily script to generate predictions for all customers in a database.
- c.A data scientist saving a newly trained model to a cloud storage bucket.
- d.Analyzing model performance metrics after a new model has been deployed.
Why? this is the answer
Model serving is designed to operationalize a model as a live, networked service for real-time predictions on demand, as exemplified by instant fraud detection. Batch processing, like a daily script, is explicitly mentioned as a scenario where model serving is often overkill.
Just read this? Test yourself on what you have been reading.
Read the original → en.wikipedia.org
- #mlops
- #model serving
- #machine learning
- #deployment
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
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.
We are hiring for this. Open roles that interview on mlops — each one lists the topics its interview covers.
See open roles