Guide

Reliability

Cancellation

When a user taps stop or closes the tab, their connection closes. The server should treat that as a cancel: stop decoding and free the request's KV cache. Otherwise the GPU keeps making tokens nobody reads, and waiting requests can't use that space. Every layer in between, like a proxy, must pass the cancel on.

Retries and streaming

A retry is safe before the first token is sent, because the user saw nothing. After streaming starts, a new try makes a new answer, which may repeat or change the text. Then it is better to show the failure and let the user start a clean answer. Retries can also swamp a busy server, so wait longer before each try (backoff), add some randomness, and cap the tries.

Running out of memory

When the KV cache fills mid-request, a good engine preempts: it pauses one request to resume later, or fails just that one. The server keeps running for everyone else. Guard memory up front: cap prompt length and max output tokens, reject prompts that are too long with a clear error, and keep some VRAM free as headroom.

Graceful deploys

A graceful deploy drains a replica first. Mark it not ready, so the router stops sending it work, let its streams finish, then replace it. Do one replica at a time, and send traffic to a new one only once it reports ready. A drain time limit trades deploy speed against cutting very long streams.

Failure tests

Break things on purpose before users do: kill a worker, flood it with traffic, send bad input, or slow a service it calls. Then check that traffic moves, busy replies appear, bad input is rejected, and timeouts fire. Start in a test copy, then test carefully in production.

Remember

  • Cancel work for users who left.
  • Retry quietly only before the first token.
  • One request running out of memory must not crash the server.
  • Drain before you replace.
  • Find weak spots with tests, not outages.