Design a Stateless Generative AI Chat Service
Design a highly available text-generation service that streams model responses, scales scarce inference capacity, recovers from failures, and exposes useful operational metrics.
Problem statement
For this exercise, assume users submit independent text prompts to a ChatGPT-style service and receive token-streamed responses. The active client may keep an in-memory transcript long enough to render a long conversation, but server-side conversation persistence and retrieval are out of scope.
The service must scale inference capacity, remain available through component and model-worker failures, apply fair admission control, and expose metrics that let operators detect saturation and user-visible degradation.
Define what happens when generation fails before or after streaming begins, keep one request from being executed concurrently by multiple model workers, compare SSE with WebSocket delivery for this interaction, and explain how the client remains responsive as the visible transcript grows.
What to build
- A user can submit an independent text prompt and receive a streamed model response.
- The service enforces per-tenant limits and rejects or queues excess work predictably.
- The service reports a clear terminal outcome when inference fails before or during a stream.
- Operators can measure request, queue, inference, stream, and failure behavior end to end.
- A client can incrementally render a long in-memory conversation while consuming the current token stream without requiring server-side conversation persistence.
At scale
- For this exercise, assume 5,000 prompt submissions per second at peak, with tenfold traffic bursts lasting up to one minute.
- For this exercise, target a two-second p95 time to first token for admitted requests and stream subsequent tokens without application-layer buffering.
- For this exercise, assume inference workers are the scarce resource and a single regional worker pool can become unavailable.
- For this exercise, retain request-scoped status and idempotency state for one hour, but do not persist prompt or response text after the request finishes.