On this page
Serving is an API design problem
Exposing a model through an API creates a contract beyond the weights. Validation, identity, error codes, timeouts and rate limits belong to that contract. The application may expect the same JSON structure and failure behaviour even when the underlying model changes. Streaming adds another decision when the client disconnects: whether work continues or is cancelled. Request identifiers and traces make it possible to understand where those paths diverged.
Prefill, decode and batching strategies
Long input processing happens during prefill; token-by-token generation happens during decode. Batching can improve GPU utilization but may force requests to wait. Continuous batching aims to mix requests arriving at different times more flexibly. Scheduler decisions affect p95 latency and fairness. If long prompts delay short questions, consider queue separation or priorities. Test every optimization against actual input/output token distributions; a single-size synthetic benchmark is often misleading.
How does the KV cache affect memory capacity?
KV caching reduces recomputation by storing keys and values for past tokens, but concurrent sessions increase memory pressure. Planning solely from model-weight size is insufficient. Include cache, activations, workspaces and runtime reserves. Long-context requests can affect the capacity available to others. Techniques such as paged attention improve cache management but do not eliminate the need to test maximum concurrency and output lengths. Define clear overload behavior before memory exhaustion becomes a production incident.
How should quantization be evaluated?
FP16, INT8 and 4-bit representations can reduce memory and sometimes improve speed depending on hardware. Lower precision can also change numerical behavior, so accuracy is not automatically preserved on every task. Evaluate quantization together with supported kernels and runtime implementations. Halving weight-file size does not mean halving end-to-end latency. Run regressions on rare labels, numerical output and tool behavior, using identical batch and input conditions for comparisons.
Latency, throughput and cost are different metrics
Latency measures waiting time for a request; throughput measures completed work per unit time. Optimizing aggregate throughput can make first-token response worse for some users. p50, p95 and p99 capture different parts of the latency distribution. Tokens per second and requests per second are not interchangeable when outputs vary in length. Total cost includes hardware, power, idle time, autoscaling and provider calls. The objective is not merely maximum throughput on a benchmark chart.
Workload-driven capacity planning
Characterize arrivals, input tokens, output length, concurrency and priority classes separately. Bursty traffic can require very different capacity from the same average load. Little's law, L = λW, relates average work in system, arrival rate and time in stable systems, but is not a standalone capacity guarantee. Load tests should ramp traffic and include long requests. Rate limits, backpressure and defined timeout behavior protect quality during overload. Autoscaling must account for cold starts and model loading.
Caching, routing and fallback in serving
Prefix or answer caching can reduce repeated work but creates privacy risk when user-specific content is reused under the wrong cache key. Routing simple requests to smaller models may save cost if backed by reliable evaluation. Fallback during an outage preserves availability but can change quality and output conventions. Test every route separately. During degraded service, a clear limitation or controlled error is often safer than pretending every answer has identical reliability.
Versioning, canaries and rollback
A new model or runtime version can silently change quality and performance. Pin weights, tokenizer, prompts, quantization, runtime and API schema together. Canary or shadow traffic can expose problems under representative requests with limited risk. Monitor output validity and failure categories as well as average latency. Practice rollbacks and ensure the old model is compatible with any cache or retrieval index that remains. Monitoring continues after rollout is declared complete.
Short questions and long documents sharing one service
Illustrative scenario; not a measured project result.
Imagine a support application receiving many short questions and a few very long document requests each minute. Average tokens per second can hide prefill cost and queueing delay. User-perceived TTFT, p95 response time and timeout rate measure different aspects of quality. This workload is illustrative and not a benchmark of a particular server.
Waiting time that token throughput does not explain
When short questions and long-document requests share a queue, average token throughput can look healthy while some users wait a long time for the first response. Model weights fitting in memory do not establish that concurrent sessions will fit; the KV cache adds another load. Serving extends beyond the model file to queue behaviour, cancelled work, output contracts and rollback, all of which shape the application users experience.
Frequently asked questions
Does high tokens/s mean the service feels fast?
Not always. TTFT, queueing and p95 end-to-end latency also matter.
Does quantization always deliver the same gains?
No. Hardware, kernels, architecture and task sensitivity change outcomes.
Is fitting model weights in memory sufficient?
No. KV cache, activations and concurrent sessions also consume memory.