Preparing your design workspace

Loading the problem and your latest saved attempt…

Design an Embeddable Streaming Chat Agent

Design an origin-bound chat widget that streams agent responses, pages long histories, resumes interrupted sessions, and remains observable.

Problem statement

For this exercise, assume an authenticated host application initializes an origin-bound chat widget. A user can start or resume a conversation, submit one message at a time, watch an agent response stream into the widget, cancel an active generation, and page older history while scrolling.

Every conversation, message, and generation has a stable identifier. Streamed deltas carry increasing sequence offsets, and a reconnecting widget resumes from a durable cursor without duplicating visible text.

Durable message storage is authoritative. Immutable history pages may be cached with a version cursor, while the widget renders only a bounded visible window and preserves scroll position across page loads and cache misses.

Operators need to measure widget bootstrap time, time to first token, inter-token gaps, completion, reconnect and resume outcomes, cache behavior, duplicate or dropped deltas, and client long tasks.

Design the browser integration, public APIs, streaming path, generation coordination, history storage and caching, virtualized rendering boundary, recovery behavior, security boundary, and observability.

Model training, retrieval-augmented generation, moderation policy design, voice or video chat, and anonymous public embedding are outside scope.

What to build

  1. An authenticated host application can initialize an origin-bound widget and obtain only the conversations and capabilities authorized for the current user.
  2. A user can submit a message, receive one ordered streamed response, cancel it, and resume after a transient disconnect without duplicate visible text.
  3. A user can resume a conversation and page older messages through a virtualized viewport that preserves stable ordering and scroll position.
  4. Operators can detect generation, transport, cache, and browser-rendering failures and recover sessions without silently losing accepted messages.

At scale

  • For this exercise, assume 100,000 concurrently connected widgets and peaks of 10,000 newly admitted generations per second.
  • For this exercise, target a two-second p95 time to the first visible token for admitted work and preserve the ordering of every visible delta.
  • For this exercise, retain one year of pageable text history, with conversations that may contain hundreds of thousands of messages.
  • For this exercise, a healthy reconnect should resume an active stream or produce an authoritative terminal state within five seconds without duplicating text.