Sub topic 16
When to use a dedicated model server
This chapter assumes you have built the FastAPI service from the earlier chapters. You should know how it loads a model at startup, validates input, and handles batching, concurrency, and scaling. Here you decide whether to keep that hand-written API or move to a purpose-built model server.
What a model server is
A model server is a program built only to run models behind a network interface. You give it a model file and a small configuration. It supplies the HTTP or gRPC endpoints, model loading, request batching, and metrics.
Common examples include NVIDIA Triton Inference Server, TorchServe, TensorFlow Serving, BentoML, and KServe. They differ in the model formats they support. Several of them cover the same features.
Your FastAPI service does the same job, but you wrote every part yourself.
What a model server adds
The earlier chapters had you build several features by hand. A model server often provides them out of the box.
| Concern | Hand-written FastAPI | Dedicated model server |
|---|---|---|
| Dynamic batching | You write queueing code | Built in, tuned by settings |
| Multiple model versions | You manage paths and routes | Served side by side from a model repository |
| GPU scheduling | You manage devices in your code | Handled by the server |
| Metrics | You add logging and counters | Latency and throughput exposed by default |
| Custom business logic | Plain Python, any shape | Needs a plugin, wrapper, or separate service |
| Operational effort | One small codebase | A new system to learn, deploy, and upgrade |
Dynamic batching is the biggest difference. The server waits a few milliseconds, groups requests that arrive close together, and runs them as one batch. This raises throughput without making clients send batches themselves.
Deciding which to use
Start with the hand-written API and move only when a concrete problem justifies it.
Keep FastAPI when:
- The model is small and fast, like the iris classifier.
- Traffic is modest and one or a few replicas handle it.
- Your service does significant work around the model, such as feature lookups or business rules.
- Your team already runs web services and has no capacity for another system.
Consider a model server when:
- The model needs a GPU and you want to keep it busy.
- Request volume makes batching worth tuning.
- You serve many models, or several versions of one model.
- Your platform team already standardizes on one server.
Common mistakes
- Adopting a server too early. A scikit-learn forest does not need Triton. The extra system costs more than it saves.
- Forgetting the pre- and post-processing. A model server runs the model, not your validation or feature code. Many teams keep a thin FastAPI service in front. It validates input and calls the model server.
- Ignoring format conversion. Some servers need ONNX or another format, so you must export and test the model again.
- Assuming it removes the need for tests. You still need contract tests, health checks, and monitoring.
Exercise
Your team serves a 20 MB scikit-learn model at about 5 requests per second. A manager proposes moving it to Triton "to be production-ready." What do you recommend, and what change would make you reconsider?
Show answer
Keep the FastAPI service. The model is small, the traffic is low, and a model server adds a new system to run without solving a current problem. Reconsider if the team moves to a GPU-based deep learning model, if traffic grows until dynamic batching would clearly raise throughput, or if the number of models and versions becomes hard to manage by hand.