Suppose a generative assistant already has weights and can answer one request. The next questions are operational: who accepts a request, decides how long it waits, allocates its cache, stops wasted work after a failure, and safely replaces the model?

This is a teaching system, not a company's internal architecture. Every calculation states its assumptions; none is a measured result for a particular GPU or framework.

Which layers handle a request?

In one lineA request passes entry, routing, engine scheduler and workers; deployment control loads, warms and drains replicas. Cancellation must reach the engine.

Start with one request, then separate the decisions happening alongside it. These are responsibilities, not a requirement to deploy every step separately.

Request path

  1. The client supplies input, a deadline, and cancellation
  2. The entry checks authentication, limits, and admission
  3. The router chooses a ready replica
  4. The engine queues work, allocates KV, and schedules computation
  5. Workers execute the model and communication
  6. Tokens stream back to the client

Deadlines and cancellation must reach the engine, not stop at the entry.

Deployment and capacity

  1. Obtain validated weights and configuration
  2. Load, warm up, and check readiness
  3. Register ready replicas with routing
  4. Use queue and cache measurements to decide scaling
  5. Stop new assignments to old replicas, then drain and retire them

The engine supplies measurements; control adjusts capacity. New resources are not instantly ready.

Layer Decision Information to pass onward Measurements
Entry Is the request valid, and can it still be admitted? Request ID, deadline, authorization scope, input limits Rejections, input lengths, entry overhead
Replica routing Which ready replica accepts it? Model version, cache-related information, remaining time Replica load, routing delay, version distribution
Engine scheduling Which tokens run this step, and where does KV live? Computed tokens, sampling state, cancellation Queue time, cache occupancy, preemption, batch composition
Workers Which operators and collectives execute? Tensors, execution plans, parallel groups Kernel time, bandwidth, communication waits, failures
Deployment control Load, warm up, shift traffic, drain, roll back Ready versions, health, resource requests Time to readiness, failed releases, capacity shortfalls

For example, the vLLM V1 architecture separates HTTP/input handling, engine-core scheduling and KV management, and GPU-worker model execution. These responsibilities provide useful source-reading entry points; process layouts and options should match the deployed version. How one engine batches each round and handles cancellation is in What happens between an LLM request and the answer on screen?.

Choosing vLLM versus SGLang is not simply “throughput versus caching.” Check models, hardware, parallelism, quantization, and integrations, then compare on the same workload. The framework chapter covers mechanisms and ecosystems. Replacing the engine does not remove admission control, recovery, or end-to-end evaluation.

Three decisions that are easy to confuse

In one lineChoosing a replica, choosing this step's requests and admitting a new replica are different schedules. A started process is not a warmed-up replica.

Decision Typical responsibility Not the same as
Which replica receives this request? Gateway and routing Which tokens the engine computes in this step
Which requests enter the next computation? Engine scheduler How much capacity the cluster allocates to the service
When can a new replica accept traffic? Deployment and resource control A process starting successfully before weights load and warmup finishes

There are several kinds of scheduling. Naming the scheduled object and the time scale matters more than memorizing a component name. Different teams may own these layers, so their interfaces need to carry deadlines, cancellation, versions, and failure reasons.

A slow response may not be slow model computation

In one lineIn the example, queueing is 80 of the 156 ms to first token; cutting compute by 20 ms gives 136 ms. Per-layer p99s do not sum to end-to-end p99.

Prefill processes the input; decode continues generation. Users also wait for preparation, queues, and transport. Consider this simplified request:

Stage Assumed duration What the user is waiting for
Input validation and preparation 6 ms Entering the service
Queueing 80 ms Available resources
Prefill through first-token readiness 60 ms Input computation and initial sampling
Delivery of the first token 10 ms Serialization and transport
Each subsequent token arrival interval 20 ms Combined computation, scheduling, and delivery

The 60 ms includes initial sampling, so time to first token (TTFT) is:

\[ T_{\rm first}=6+80+60+10=156\ \mathrm{ms}. \]

For exactly 100 output tokens with a fixed subsequent arrival interval of 20 ms, completion time is:

\[ T_{\rm complete}=156+(100-1)\times20=2136\ \mathrm{ms}. \]

Reducing computation from 60 to 40 ms brings TTFT from 156 to 136 ms; queueing still dominates much of the wait. Conversely, batching that increases throughput by waiting longer may feel slower to the user.

This is a single-request decomposition. Adding per-layer p99s does not give end-to-end p99. Trace complete requests and compare by input length, output length, cache behavior, and traffic period. Specify whether inter-token latency (ITL) is measured at the engine or client: buffering and transport affect the two differently.

How does KV cache limit admission?

In one lineIn the example, at 32 requests, 8K instead of 2K inputs raises the KV budget from 10 to 34 GiB. A request cap is not a token budget.

Assume an ordinary GQA Transformer with 32 layers, 8 KV heads, head dimension 128, and 2 bytes per K or V element. Initially ignore page waste, shared prefixes, sliding windows, and other cache compression. Logical KV per cached token per sequence is:

\[ b_{\rm token}=2\times32\times8\times128\times2 =131072\ \mathrm{bytes}=128\ \mathrm{KiB}. \]

The first 2 accounts for K and V; the last is bytes per element. This is logical KV across one complete model, not necessarily per-device allocation under arbitrary parallelism. Sharding and replication change placement; architectures such as MLA need a different formula.

Request-length budget Logical KV per sequence Total for 32 sequences
2,048 input + 512 maximum output = 2,560 tokens 320 MiB 10 GiB
8,192 input + 512 maximum output = 8,704 tokens 1,088 MiB 34 GiB

The same “32 concurrent requests” differ by 24 GiB just by changing input length. Input plus maximum output is a conservative budget; an engine may allocate incrementally rather than reserve all output space immediately. It still needs a policy for cache exhaustion if all admitted requests approach their limits.

Subtract weights, peak activations, runtime allocations, and headroom before defining the KV budget. Even 10 GiB remaining does not guarantee the first row fits: allocation granularity and temporary storage are excluded. A request-count limit is not a token-budget limit.

Prefix caching reuses computation for genuinely identical, compatible prefixes, not merely similar text. Hit rates depend on routing, eviction, and traffic. Evaluate both cold caches and representative reuse instead of reporting only an ideal warm-cache workload.

Replication, model parallelism, and disaggregation solve different problems

In one lineReplicas, TP/PP and a prefill/decode split each solve one problem at a cost. In the example, 125 ms of KV transfer on the critical path outweighs 40 ms saved.

Choice Main purpose Added cost or constraint
Independent replicas More requests than one replica can handle Repeated weights, fragmented caches, load balancing
Tensor parallelism (TP) Split model computation and storage Per-layer communication; interconnect sensitivity; workers execute together
Pipeline parallelism (PP) Place different model layers separately Transfers between stages, pipeline bubbles, scheduling complexity
Prefill/decode disaggregation Reduce interference and provision phases separately KV transfer, capacity balance, routing, and recovery complexity

A TP group is generally one logical replica, not several complete replicas free to accept unrelated work independently. Losing a worker may stop or require rebuilding the group. Routing to another replica does not automatically move its KV state there.

Disaggregation needs a transfer budget too. SGLang's documentation explains how prefill can interfere with decode. For a framework-independent example, transferring 1 GiB of KV at an effective 8 GiB/s takes 125 ms for the payload alone, before queueing and protocol overhead.

If it removes only 40 ms of interference and all 125 ms sits on the critical path, single-request latency does not improve. Whether overlapping transfer, greater capacity, or better tail latency compensates needs a workload-specific measurement. A more elaborate architecture is not automatically a better one.

Cache-affinity routing has a similar tradeoff. Sending a prefix back to its previous replica can save computation while creating a queue at a hot replica. Compare computation saved against waiting added, not hit rate alone.

How does training connect to this service?

In one lineKeep updates off the request path and test on small traffic first. Error-free training can still change the objective: 2 instead of 2.5 in the example.

Model updates should not sit on the request's critical path. A minimal offline update flow is:

Produce a recoverable training result

  1. Fix the data snapshot and transform versions
  2. Sample, shard, and construct batches
  3. Run forward, backward, gradient synchronization, and updates
  4. Save recoverable training state

Data position and optimizer progress belong to recovery state too.

Validate before serving

  1. Run task evaluations and regression checks
  2. Prepare serving weights, tokenizer, and configuration
  3. Load, warm up, and validate on small traffic
  4. Expand traffic after checks pass

Model updates enter the deployment path above without blocking active requests.

DDP typically replicates the model and synchronizes gradients. FSDP2 shards training state, gathers parameter groups for computation, and uses the corresponding gradient communication. Consider memory and communication together, not forward speed alone. The PyTorch FSDP2 tutorial explains gathering, computation, and prefetching; see training frameworks for the wider choice.

A subtler failure is a distributed program that runs successfully but changes the objective. Suppose two ranks have 2 and 6 valid tokens, with local mean losses of 1 and 3. If the objective averages all valid tokens:

\[ \bar L=\frac{2\times1+6\times3}{2+6}=2.5, \qquad \frac{1+3}{2}=2\ne\bar L. \]

Averaging local means equally overweights the shorter contribution. This is objective-value arithmetic. Implementing backward also requires checking gradient reduction, gradient accumulation, and global valid-token counts; changing the displayed loss to 2.5 is not a fix by itself.

Training recovery needs more than weights. Optimizer state, learning-rate progress, randomness, the data cursor, and sharding configuration determine what happens next. Serving may not need those states. The artifacts can share weights while having different purposes and validation rules.

Walk the complete path before release

In one lineBefore release, test version matching, readiness, cancellation, draining without cutting streams, and bounded retries. Use mixed input and output lengths.

Check Concrete action Expected behavior
Compatible versions Check weights, tokenizer, template, sampling configuration, and cache isolation together New and old releases do not reuse incompatible state
Readiness Send test traffic before loading and warmup finish Unready instances do not accept normal traffic
Cancellation Disconnect a client midway Cancellation reaches the queue and engine; associated resources are eventually freed
Draining Stop new assignments to an old replica; wait for active requests No silent interruption of streams; bounded handling of drain timeouts
Recovery Inject a worker failure or dependency timeout Retries have budgets, failures have an owner, queues remain bounded

Build a workload with short, medium, and long inputs and varied output limits before comparing engine speed. Peak throughput on fixed short prompts does not describe mixed-length user experience. Keep rejected and timed-out requests visible in the measurements.

Queueing, capacity, and failures turns these boundaries into small calculations and runnable models. They are estimation and debugging exercises, not production deployment configurations.