Model Serving & APIs
You'll be able to:
You can design a model serving architecture and explain latency/throughput trade-offs between batch and real-time inference.
Opening You've spent months training a large language model (LLM), but when you deploy it as an API, users complain about slow responses and incorrect answers. Your team is stuck debugging the serving architecture, unsure where to optimize.
Model Serving Architectures
What it is
A model serving architecture is the infrastructure that deploys your trained LLM as a production-ready API. It handles incoming requests, executes inference, and returns responses.
Non-obvious Production Insight
Most teams underestimate the impact of latency on user experience. An often-quoted Amazon anecdote (Greg Linden, 2006) holds that every extra 100 ms of latency cost about 1% of sales. To mitigate this, experienced engineers prioritize asynchronous processing and caching mechanisms.
Analogy for Stakeholders
Think of model serving like a restaurant kitchen. Your LLM is the chef, but the kitchen's layout, staffing, and workflow determine how quickly and accurately dishes (responses) are served. A well-designed serving architecture ensures that your "chef" can work efficiently, even during peak hours.
Batch vs Real-time Inference
What it is
Batch inference processes multiple requests together, while real-time inference handles each request individually. The choice between these approaches depends on your use case and performance requirements.
Non-obvious Production Insight
Batching amortises weight reads across requests, raising throughput at the cost of per-request latency; real-time serving minimises per-request latency at lower hardware utilisation. There is no accuracy difference between the two.
Analogy for Stakeholders
Imagine a taxi service. Batch inference is like a bus that picks up multiple passengers at once, while real-time inference is like a personal taxi that takes each passenger directly to their destination. Both have trade-offs: buses move more passengers per trip, but each passenger waits for the bus to fill and takes a less direct route, while taxis get each passenger there fastest but cost more per ride.
Caching Mechanisms
What it is
Caching stores frequently accessed data in memory or on disk, reducing the number of requests made to your LLM. This improves response times and reduces latency.
Non-obvious Production Insight
Effective caching requires careful consideration of cache invalidation strategies, as stale responses can be worse than slow ones. Implementing a time-to-live (TTL) or content-based eviction policy can help ensure that cached responses remain accurate.
Analogy for Stakeholders
Think of caching like a browser's back button. When you revisit a page, your browser loads it from memory instead of re-downloading the entire page. Similarly, caching in model serving stores frequently accessed data so that your LLM doesn't need to recompute it every time.
The Gateway: Rate Limits, Retries and Fallbacks
What it is
In production every request passes through a gateway in front of the model. It authenticates the caller, enforces rate limits, checks the cache, and decides what happens when the model call fails.
Rate limiting works at two levels. The provider limits your whole organisation. Anthropic's API, for example, meters requests, input tokens and output tokens per minute with a token-bucket algorithm, and answers HTTP 429 when you exceed them, often with a retry-after header saying how long to wait. Your gateway adds its own per-user or per-tenant quotas, so one heavy customer cannot spend the shared provider budget for everyone.
Fallbacks send a failed or timed-out request somewhere else: another deployment, another provider, or a smaller model. Gateways such as LiteLLM can configure separate fallback chains for context-window overflows and content-policy refusals, plus a general chain that covers rate-limit and other errors.
Non-obvious Production Insight
Both mechanisms fail in ways that look like success. Clients that retry immediately, or with fixed delays, retry in step, so a brief rate-limit spike becomes synchronised waves of load. The fix is exponential backoff with random jitter, honouring retry-after when it is present. A fallback to a weaker model keeps uptime at 100% while answer quality drops. Unless you record which model served each request and alert on the fallback rate, nobody notices.
Analogy for Stakeholders
The gateway is the restaurant's host stand. It limits how many tables one party can book, so a single group cannot fill the room. When the head chef is swamped, it sends orders to a second kitchen. That works, as long as someone checks what the second kitchen serves.
Failure Modes
| Name | Root Cause | Observable Signal |
|---|---|---|
| Stale Cache | Cache invalidation policy not properly implemented | Correct prompt structure, factually wrong answers |
| Inference Bottleneck | Insufficient resources allocated for inference | High latency, slow response times |
| Serialization Overhead | Inefficient serialization and deserialization of requests and responses | Increased latency due to overhead |
| Retry Storm | Clients retry 429s and timeouts immediately and in step | Request volume spikes in waves right after each rate-limit episode |
| Silent Fallback | A fallback model serves traffic and nothing records which model answered | Uptime normal while answer quality and satisfaction fall |
Swipe sideways to see every column →
Stakeholder Communication
When explaining model serving architectures to non-technical stakeholders, use analogies like:
- "Our LLM is like a chef in a kitchen. We need to design the kitchen's layout and workflow to ensure our chef can work efficiently."
- "Model serving is like a taxi service. We need to choose between batch inference (like a bus) and real-time inference (like a personal taxi) based on our performance requirements."
- "Caching is like a browser's back button. We store frequently accessed data in memory so that our LLM doesn't need to recompute it every time."
Check Yourself
Module Mission
15–30 minSketch a production serving architecture for an LLM API: what components handle rate limiting, caching, fallbacks? Name one failure mode for each.
Loading your work…
Curated Materials
1hThe deep work happens here — the lesson is your briefing.
Live on aiqbench
This lesson's subject on the rest of the site, today.
In the news, last 30 days
- CA-RAG: Constraint-Aligned Retrieval for Structurally Faithful Long-Form GenerationarXiv ·
- ITC Neocloud raises $2.5M in share placing amid AI infrastructure pivotDealroom.co ·
- IQM Quantum Computers Sells 54-Qubit Radiance R3 System to South Korean Quantum-AI Infrastructure Firm QAIQuantum Computing Report ·