Model serving & latency
FastAPI for classical models, batching, ONNX export; vLLM and quantization for LLMs. Know your p99 and what dominates it (tokenization? GPU queue? network?).
The mental model
Model serving is a restaurant kitchen at dinner rush. Training built the recipes; serving is now feeding a queue of hungry, impatient tables under a clock. The GPU is the one expensive chef everyone waits on. Latency is how long a single table waits for its plate; throughput is how many plates leave the kitchen per minute; and the two fight — batching plates for the chef raises throughput but makes the first table wait for the others. Every serving decision is a seat at this table: batch bigger for cost, or serve smaller for speed.
The mental shift from notebooks is that a model in a notebook is a function you call; a model in production is a service you operate under a latency budget. The interviewer's tell is whether you know your p99 and what dominates it. "It's fast" is a junior answer. "p99 is 180 ms, of which 40 ms is tokenization, 90 ms is GPU queue wait under load, and 20 ms is network" is the answer that says you have actually measured a serving path. The number that matters is almost never the average — the average hides the tail, and the tail is what pages you.
The single load-bearing rule for classical models: load the model once at startup, never per request. The single load-bearing rule for LLMs: the GPU is the bottleneck, so the whole game is keeping it busy without making any one request wait too long — which is what continuous batching and the paged KV cache exist to do.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision