Distributed ReliabilityLatency and load evidencePrincipal
How should streamed inference handle slow clients without unbounded buffering or stranded GPU state?
By Amit Kumar2 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
An inference worker generates faster than mobile clients consume their response streams. Trace where bytes can accumulate between worker, gateway and transport. Design per-request buffering, backpressure, delivery deadlines and cancellation, including what can be claimed about generated versus delivered tokens and how to test a slow reader.
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
An inference server produces tokens faster than a mobile client can read its stream. Maybe the radio connection is weak, or the browser tab stopped consuming events. The GPU can keep generating while an API gateway buffers chunks in memory. If that queue has no bound, a few thousand slow clients can exhaust the gateway even when GPU utilization looks normal.
A hypothetical 10,000 slow streams with a 64 KiB application buffer each already retain 625 MiB of payload, before object overhead, socket buffers or model attention state. Bounding that queue limits one source of memory, but pausing generation may still retain the request’s attention cache on the GPU. The policy has to bound both delivery lag and the lifetime of that upstream state.
Trace each boundary. The model worker emits token events to the gateway, the gateway writes to an HTTP or RPC stream, and the transport eventually applies flow control. Node.js stream documentation says a writable's write() can return false and a producer should wait for drain. gRPC flow-control guidance similarly explains that stream writers can be held back by receiver capacity. Neither mechanism automatically limits an application's separate queue between a GPU worker and the network handler. That queue must have an explicit policy.
I would cap queued bytes or token events per request and measure lag between generation and delivery. When the cap is reached, pause upstream production if the scheduler and model worker support it. If they cannot pause cleanly without holding scarce KV blocks forever, set a delivery deadline and terminate the request with an honest partial-stream status. Release worker and attention-cache resources after cancellation is acknowledged. Coalescing UI events can reduce per-token overhead, but it cannot silently drop generated content if the API promises the complete answer.
The policy also affects billing and audit. Distinguish tokens generated, tokens queued, tokens delivered and tokens acknowledged if the protocol has acknowledgments. A network write completing only means bytes reached a local buffer, not necessarily the user's screen. Do not claim exactly what the user read without an application-level acknowledgment.
To test it, throttle one client to a few bytes per second while other requests run. Watch gateway resident memory, per-request queue depth, active attention-cache lifetime and cancellation latency. A fast-client load test will miss the failure entirely. The right outcome is bounded memory and explicit lifecycle behavior under slow consumption.
Related questions
Keep practising distributed reliability
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