Requirements: multi-turn chat, streaming tokens, millions of users, low time-to-first-token (around 1 s), safety, and cost control.
Request path: client, API gateway (auth, rate limits), chat service, inference cluster; stream tokens back with Server-Sent Events or WebSockets.
Conversation state: store messages in a database keyed by conversation ID; trim or summarize history to fit the context window; reuse the shared prefix (system prompt) with prefix/KV caching.
Inference: GPU pools with continuous batching, autoscaling on queue depth, separate pools per model size, and routing of easy requests to smaller models.
Safety: input and output moderation, with a fast classifier in the streaming path.
Reliability: timeouts, retries, a fallback model, and graceful degradation under load (queueing, shorter limits).
Observability: time-to-first-token, tokens per second, error rate, cost per request, and user feedback.
Loading…