Model and Inference EngineeringKV cache and capacityPrincipal
How would you bound pending attention-cache transfers and decoder reservations in split inference?
By Amit Kumar4 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
Separate prefill workers produce state faster than a shared network and decode pool can accept it. Decoder memory is reserved while transfers queue, and short requests miss deadlines despite free compute. Design joint admission, ownership, cancellation and recovery across the transfer, with explicit byte budgets and compatibility checks.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Prefill processes the prompt and builds key-value (KV) attention state. Decode consumes that state to generate new tokens. Splitting those phases creates a pipeline with three scarce resources: prefill execution, transfer bandwidth and destination cache memory. Finishing prefill faster can increase the amount of state waiting between them. A free decoder cannot serve a request whose state has not arrived, while memory reserved for a delayed transfer can prevent another request from entering.
How much data is that? For a conventional full-attention cache, a rough uncompressed estimate is 2 × layers × KV heads × head dimension × cached tokens × bytes per element. The two is for keys and values. Actual bytes depend on cache dtype, attention architecture, which layers retain which positions, transfer granularity and whether some prefix is already local. A million-token advertisement does not mean every request transfers a million tokens, but long prompts can turn this handoff into a material network operation. P/D-Serve includes KV transfer in its disaggregated serving analysis, and NetKV studies how network topology and congestion affect decode placement.
For a hypothetical 32-layer model with 8 key/value heads of 128 components, 8,192 cached tokens and two-byte values, the raw cache is one GiB. Ten such transfers require ten GiB. At an effective shared throughput of two GiB per second, completing all ten takes at least five seconds even before scheduling overhead. Their individual latencies depend on scheduling and contention. This is a byte budget, not a measured deployment result.
I would break first-token latency into queue time for prefill, prefill execution, KV serialization or registration, transfer wait, actual transfer, decode admission and first decode step. Compare sizes and network paths by request, not fleet-average GPU utilization. A fast prefill worker in one rack paired with a lightly loaded decoder across a congested link may be worse than a busier decoder with local KV. Also check whether the decoder reserves capacity while waiting for KV and whether backpressure allows transfers to pile up. A bandwidth estimate from bytes divided by nominal link rate is only a lower bound when transfers contend.
Before starting more prefill work, obtain a bounded grant for its source state, transfer work and compatible destination capacity, or use an explicitly bounded staging pool instead. Track bytes waiting and moving, not only request count. Apply backpressure before allocating unbounded prompt state. A grant needs an owner, deadline and terminal release path so cancellation cannot strand decoder reservations forever.
A transfer should become decode-eligible only after the receiver verifies completion and the agreed model/cache descriptor. Partial writes must remain in a receiving state. If a producer dies, either resume under the chosen transport contract or recompute from accepted prompt history. If a request is cancelled while a device copy is still using memory, wait for or fence that actual use before reusing the blocks. A lease timeout alone cannot stop a late writer. Keep a generation identity on retries so an old completion cannot activate a new request’s allocation.
The scheduler’s decision is joint. Choose a prefill worker and decoder based on compute queue, compatible model revision, KV locality, network cost and the request's latency target. For short prompts, local prefill plus decode may beat disaggregation because it avoids the handoff. For long prompts or heavy prefill contention, separation can still win. Cache transfer compression or lower-precision KV can save bytes, but may add compute or change quality, so measure completed-request latency and accuracy together. Do not just optimize transfer microbenchmarks.
The question about whether to split inference compares phase interference and end-to-end cost. This narrower design must establish bounded in-flight state and safe ownership when the network is slower than the producers. Test a stalled link, cancellation during transfer, producer crash, decoder loss and a delayed old completion. Assert both eventual reservation release and that decode never reads a partial or incompatible artifact.
If the interviewer asks whether to buy more decode GPUs, I would first inspect the bottleneck. More decode workers cannot fix a saturated shared link and may create more cross-rack traffic. Run a mixed prompt-length load with realistic concurrency, record transfer bytes and p95/p99 per stage, and compare colocated versus disaggregated paths under the same arrival process. Should prefill and decode run on different GPUs? asks whether to separate prefill and decode. This page asks why a separation that looks good on GPU metrics can lose on the KV handoff.
Related questions
Keep practising model and inference engineering
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux