What happens inside a model server when a request arrives?
The prompt is tokenized and processed in the prefill phase, which builds the KV cache and produces the first token. The decode phase then generates the rest one token at a time, reusing the cache. Model servers batch many requests together, and gateways route requests across servers and models.
Time to first token covers the wait before output starts; inter-token latency covers the speed while generating; end-to-end latency is the total. Throughput counts tokens or requests per second across all users. Load tests at realistic concurrency show these numbers and the service's limits.
Use in-flight batching and paged KV cache to keep GPUs busy, reuse cached prefixes, quantize to FP8 or lower where accuracy allows, and try speculative decoding. For big models, use tensor parallelism or disaggregated serving with Dynamo. TensorRT-LLM provides most of these optimizations.
Weights take a fixed amount, but the KV cache grows with context length and the number of concurrent requests. Long documents or many users can exhaust memory. Fixes include limiting maximum context or concurrency, quantizing, or adding GPUs with tensor parallelism.
How do you choose between real-time, streaming and batch inference?
Real-time serving answers users who are waiting, so latency matters most; streaming tokens makes it feel faster. Batch inference processes large volumes offline for throughput and cost. Bigger batches raise throughput but can add latency, so the right setting depends on your latency targets and budget.