
Model Serving: Deploying AI at Scale
Master the infrastructure of AI. Learn the difference between managed inference (AWS Bedrock) and self-hosted inference (vLLM, TGI). Discover how to handle thousands of concurrent requests.
Model Serving: Deploying AI at Scale
Once your model is trained, fine-tuned, and quantized, you need to expose it to the world. A standard Python script with flask isn't enough to handle real-world traffic. High-performance Model Serving requires specialized engines that handle KV Caching, Batching, and Multi-GPU orchestration.
In this lesson, we break down the three primary ways to serve an LLM in 2026.
1. Managed Inference (MaaS)
Services: AWS Bedrock, Google Vertex AI, OpenAI, Groq. Ideal For: 90% of business applications.
How it Works:
You don't manage any servers. You simply call an API (e.g., Anthropic via Bedrock). The provider handles the scaling, the hardware, and the optimization.
Pros:
- Zero infrastructure maintenance.
- Scale to millions of requests instantly.
- Pay-as-you-go. Cons:
- Higher cost per token.
- No control over the low-level model parameters.
2. High-Performance Self-Hosting (vLLM)
Tools: vLLM, Text Generation Inference (TGI), TensorRT-LLM. Ideal For: LLM Engineering teams that need maximum speed and want to minimize long-term costs.
What is vLLM?
vLLM is the current industry leader for self-hosted serving. It uses a technique called PagedAttention (similar to how computer OS manages RAM) to increase throughput by 20x - 30x compared to standard libraries.
Key Feature: Continuous Batching
Instead of waiting for one user's response to finish before starting the next, vLLM "batches" new requests into the generation cycle of existing ones. This results in incredibly low latency for all users.
graph TD
A[User 1 Request] --> B{vLLM Server}
A2[User 2 Request] --> B
A3[User 3 Request] --> B
B -- Batch Processing --> C[GPU Runtime]
C --> D[Simultaneous Streamed Responses]
3. Local Serving (Ollama / LocalAI)
Tools: Ollama, LM Studio. Ideal For: Development, private edge cases, and desktop applications.
Ollama wraps complex C++ libraries like llama.cpp into a simple, Docker-like interface. You can run ollama run llama3 and have a local API server running in seconds.
Comparative Matrix: Serving Strategies
| Strategy | Speed (Throughput) | Setup Difficulty | Best Use Case |
|---|---|---|---|
| Managed (Bedrock) | Ultra-High | Low | Standard SaaS Apps. |
| vLLM (Self-Hosted) | Highest possible | High | Specialized heavy-load apps. |
| Ollama (Local) | Low (Limited by your PC) | Zero | Dev/Research. |
4. The Inference Stack Architecture
When you deploy a self-hosted model, you aren't just running a script. You are running a Stack:
- Gateway: Nginx or Traefik (Handling SSL and rate-limiting).
- Serving Engine: vLLM (Executing the model).
- Queue/Buffer: To prevent the GPU from being overwhelmed.
- Monitoring: Prometheus/Grafana (Tracking tokens-per-second).
Code Concept: Starting a vLLM Server
If you have a GPU, running vLLM is often just a one-line Docker command.
# Running an OpenAI-compatible server for Llama 3
python -m vllm.entrypoints.openai.api_server \
--model meta-llama/Meta-Llama-3-8B \
--gpu-memory-utilization 0.9 \
--port 8000
Note: Once this is running, you can use the standard OpenAI Python client to talk to your OWN private server!
Summary
- Managed Serving (AWS/OpenAI) is fast to start but expensive at scale.
- vLLM is the king of self-hosted speed. Use PagedAttention and Continuous Batching.
- Ollama is the king of developer experience for local work.
- Serving is about Throughput (How many users can I handle at once?).
In the next lesson, we will look at Low-Latency Scaling, focusing on how to route traffic across multiple GPUs and regions.
Exercise: The CTO's Decision
Your application has grown from 10 users to 100,000 users. Your AWS bill for OpenAI has jumped to $20,000 a month. You realize you can run the same model on four H100 GPUs which would cost $4,000 a month to rent.
- Which server technology would you use (vLLM or Ollama)?
- What is the main risk of switching from Managed to Self-Hosted?
Answer Logic:
- vLLM. It is the only choice for high-throughput production workloads.
- Maintenance Risk. You are now responsible for uptime, security patches, and scaling logic that AWS used to handle for you.