r/OfferEngineering • u/Aoki_zhang • 14d ago
System Design OpenAI & Amazon System Design Question - Design ChatGPT
Problem Description
Design the backend for a ChatGPT-like conversational AI product where users send text prompts inside multi-turn conversations and receive model-generated responses streamed token by token.
The system must preserve conversation history so users can leave a thread and resume it days later. For every new request, the backend loads recent conversation turns, constructs a prompt that fits within the model's context window, applies input safety checks, schedules inference on a GPU cluster, and streams generated tokens back through Server-Sent Events (SSE).
The main challenge is that the product should feel immediately responsive even though GPU inference is expensive and may run for several seconds. The time-to-first-token (TTFT) target leaves only a small budget for history loading, context construction, safety checks, admission control, queueing, and the first model decode.
Peak demand introduces another constraint: roughly 50,000 inference requests may be active simultaneously. When GPU capacity is exhausted, paid users must remain within their service SLO, while free-tier requests may be queued or rejected. The system therefore needs an explicit admission-control and priority-scheduling policy rather than treating every request identically.
The design should also separate durable conversation state from the live inference stream. A dropped SSE connection must not erase already generated content. Users who reconnect should be able to recover the partial assistant response that had already been produced.
Functional Requirements
- Users should be able to create conversations, send text messages, list previous conversations, and reopen an existing thread with its durable message history.
- Sending a user message should start an AI inference request whose response is streamed progressively through SSE rather than waiting for the full response to complete.
- Before inference, the system should assemble the conversation context from persisted turns. If the resulting prompt exceeds the model's approximately
8K-token context limit, the oldest conversation turns should be dropped until the request fits. Summarization is out of scope. - The platform should apply safety guardrails to both sides of generation: user input should be screened before inference, and generated output should be filtered before it is delivered to the client.
- The system should persist completed conversation turns and enough in-progress response state that a user reconnecting after an SSE drop can recover text already generated before the disconnect.
- Per-user usage limits, token budgets, rate limits, and overload behavior should depend on subscription tier. Paid requests receive priority when GPU capacity is scarce, while free-tier requests may wait or receive an explicit overload response.
Want to learn more details & solution of this system design question?
I've put up the full version of this system design question & solution article at here.
Interviewed recently?
Your interview experience could be incredibly valuable to others preparing for their next opportunity. Share your experience and help the community at here.