Working through this module?
Module 05 · Page 6 of 20 · 8 sections
Model Serving and Inference Architecture
How a trained model is exposed to users: serving styles, the request flow, popular tools and the trade-offs to weigh.
What is Model Serving?
- The process of deploying a trained model and making it available for real-time or batch inference.
- It handles incoming requests, runs inference and returns the response to the user or application.
- It includes infrastructure, APIs, scaling, monitoring and security.
Why is it Important?
- Brings ML/AI models to real users.
- Handles high traffic with low latency.
- Ensures reliability, scalability and availability.
- Supports versioning, A/B testing and rollback.
- Enables cost-efficient and optimized inference.
- Monitors model performance and data drift in production.
Typical Inference Architecture
Users / ClientsWeb / mobile
Load Balancer
API GatewayAuth, rate limiting, routing
Inference ServerLoad model, run inference, auto-scale
Model StorageRegistry, versioning, artifacts
MonitoringLogs, metrics, alerts
Types of Model Serving
- Real-time Inference
- Low latency response (milliseconds). Used for chatbots and recommendations.
- Batch Inference
- Process large data offline. Used for data enrichment and reports.
- Online Serving
- Model is always available in memory. Used for real-time applications.
- Serverless Serving
- Pay per request with auto scaling. Used for low or variable traffic.
- Edge Inference
- Run models on edge devices (mobile, IoT). Used for low latency and privacy-sensitive use cases.
1
2
3
4
5
Inference Flow (Step-by-Step)
- 1Client sends a request (text, image, etc.) to the API.
- 2API Gateway validates the request (auth, rate limit).
- 3Request is routed to the inference server.
- 4Inference server loads the model (if not already loaded).
- 5Preprocess the input data.
- 6Run inference using the model.
- 7Postprocess the output (decode, format).
- 8Return the response to the client.
Popular Model Serving Tools
| Tool | Best for |
|---|---|
| TensorFlow Serving | TensorFlow models |
| TorchServe | PyTorch models |
| FastAPI | Lightweight Python API server |
| BentoML | Unified model serving framework |
| NVIDIA Triton | High performance multi-model serving |
| Seldon Core | Kubernetes-based model serving |
| Hugging Face Inference Endpoints | LLM serving |
Key Considerations
- Latency
- Optimize model and infrastructure.
- Throughput
- Handle a high number of requests.
- Scalability
- Auto scaling with load.
- Model Versioning
- Support multiple model versions.
- Monitoring
- Track latency, errors and drift.
- Security
- Authentication, authorization and data privacy.
- Cost Optimization
- Use the right instance type and batching.
1
2
3
4
5
6
7
Real-world Examples
- ChatGPT
- Real-time LLM inference at scale.
- Netflix
- Recommendation model serving.
- Uber
- ETA prediction model serving.
- Search ranking model serving.
- E-commerce
- Product recommendation.
- Healthcare
- Medical image analysis inference.
1
2
3
4
5
6