Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Persistent Multi-Thread AI Chat

Let an authenticated user start a new chat or reopen a previous thread and stream the next assistant reply from durable history.

Problem statement

Design a ChatGPT-like chat service whose hard product pressure is starting a new chat and continuing a previous chat.

For this exercise, assume an authenticated user acts within one tenant workspace, starts a new chat or reopens a previous thread, streams the next assistant reply, searches committed messages in that workspace, and may edit a prior user message by creating a new revision while preserving history.

No read, stream, search result, edit, or cache entry may cross a tenant boundary. For this exercise, assume chat messages survive process restart and remain readable when the thread is reopened. For this exercise, assume 10,000 new prompts per second and 30,000 concurrent streams with p99 first-token under 500 ms.

For this exercise, assume model training, billing invoices, voice audio, and multi-region active-active are out of scope. For this exercise, assume a focused follow-up will ask how a reopened thread still shows every committed message after a process restart.

What to build

  1. An authenticated user can start a new chat thread and send the first prompt.
  2. The user can reopen a previous thread, read its messages, and send the next prompt.
  3. The service streams the assistant reply for an admitted prompt.
  4. Committed messages remain readable after process restart when the thread is reopened.
  5. Every thread, message, stream, cache lookup, and search result is authorized within one tenant workspace and cannot expose another tenant's data.
  6. An authorized user can search committed messages within the active tenant workspace and open a result only after durable ownership is revalidated.
  7. An authorized edit creates an immutable message revision, preserves prior bytes and reply lineage, and resolves any race with an in-flight assistant reply.

At scale

  • For this exercise, assume 10,000 new prompts per second.
  • For this exercise, assume 30,000 concurrent streams.
  • For this exercise, target p99 time to first token under 500 ms.
  • For this exercise, thread history must remain readable after process restart; in-memory-only chat is out.
  • Tenant identity is part of every authoritative key and authorization decision; search indexes and caches are projections and cannot grant access.
  • Message edits append immutable revisions, and committed search updates may lag while direct thread reads remain authoritative.