Design a ChatGPT-Style Chat Service with Server-Sent Events Streaming
Company: Workday
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Onsite
Design the backend of a ChatGPT-style chat product. Users create conversations, send messages, and watch the assistant's reply appear token by token as it is generated. Model inference is out of scope: assume an internal inference service that accepts a conversation's context and streams the generated tokens back. The discussion centered on delivering the streamed reply to the client with Server-Sent Events (SSE), so that part of the design should go deepest.
```hint Follow one reply
Trace a single assistant reply from the moment the user presses send until the last token is on screen, and list every hop that must hold a connection open.
```
```hint Connections drop
Ask what the client sees when its connection breaks halfway through a reply, and what the server must have kept so the client can continue instead of starting over.
```
### Constraints and Clarifications
- The inference service is a black box that streams tokens; a single reply can take many seconds to finish.
- Conversations are text, and their history is stored so users can return to them.
- Model training and inference internals are not part of the design.
### Clarifying Questions
- How many users and concurrent streaming replies must be supported, and how much latency may the system add on top of the model's own time to first token?
- Must a reply survive a dropped connection or a page reload, and should it continue on another tab or device that opens the same conversation?
- Can the user stop a reply mid-generation, and should the partial reply be saved?
- Is SSE a given, or should the design compare it with WebSockets and long polling?
- Which clients must be supported (browsers, mobile apps), and do some of them sit behind proxies that may buffer responses?
### What a Strong Answer Covers
- Requirements and scale agreed first, with inference treated as a black-box streaming dependency
- Data model and APIs for conversations and messages, and whether sending a message and receiving its reply share one request or use two
- SSE mechanics: response headers, event format, event ids, heartbeats, and why SSE fits one-way token streaming compared with WebSockets
- Reconnection and resume using the last event id, backed by state the server keeps per reply, plus stopping a reply and saving partial output
- Running many long-lived connections: gateway and load balancer timeouts, proxy buffering, connection limits per server, horizontal scaling and graceful deploys
- Failure handling and observability: inference errors mid-stream, slow clients, time to first token, dropped streams
### Follow-up Questions
- A user opens the same conversation in a second tab while a reply is streaming. How does the second tab show the reply?
- You deploy a new version of the streaming servers. What happens to replies in flight, and how do you avoid cutting them off?
- Browsers allow only a few concurrent HTTP/1.1 connections per host. How does that affect SSE, and how do you avoid the problem?
- How would you meter token usage per user and enforce rate limits without slowing the stream?
Overview: Design the backend of a ChatGPT-style chat service with model inference treated as a black box, focusing on streaming replies token by token with Server-Sent Events. It tests connection handling, resuming interrupted streams, stopping generation, and scaling many long-lived connections.
Read the full Workday Software Engineer interview experience this question came from