KatInterview

Shipping a Persistent Streaming Chat Widget in a React App

System DesignModel answer
MediumModel answerSystem Designreactstreamingfrontend-architecture

Last updated

Plan how to build, test and safely release a streaming chat panel in a React dashboard, covering state, request races, token expiry, accessibility, feature flags and rollback.

Scenario

Your team is adding an in-app help chat panel to an operations dashboard used to monitor server infrastructure. Replies arrive as a live token stream over Server-Sent Events (SSE). The panel has to stay open, and keep its conversation, while the user moves between dashboard pages.

What to cover

Walk through a plan for each of the following areas.

  1. State and performance

    • Where does the conversation state live so that page navigation does not reset it?
    • How do you keep rendering fast when the history becomes long and tokens arrive many times per second?
  2. Concurrency and lifecycle

    • What happens if the user sends a new message while a reply is still streaming?
    • How do you cancel in-flight requests and release observers, listeners and timers when components unmount?
  3. Testing and resilience

    • How do you test incremental rendering, dropped connections and error states?
    • How do you verify accessibility for screen-reader users, particularly live-region announcements?
  4. Release and operations

    • How do you roll the feature out gradually, cope with a backend that is only partly available, and provide an instant kill switch?
    • How do you measure adoption without capturing personally identifiable information?

Constraints

  • Updates must feel low-latency to the user.
  • You need a fast, well-defined rollback path for serious regressions.
  • Access tokens can expire while a stream is open, so say how you would handle that.

State any assumptions (message volume, token lifetime, tokens per second) before you design.

Hints

Hint 1

Think about what must outlive route changes: mounting the panel outside the routed area and holding the stream in a store or service, not in a component, solves most persistence questions.

Hint 2

For races, give every request an identifier and an abort handle, and make every state write check that its identifier is still the active one.

Hint 3

For accessibility, consider what a screen reader does if the whole growing message is a live region, and where a separate, quieter announcement channel could help.

Hint 4

For rollout, list your first lever (a remotely controlled flag), your guardrail metrics, and the exact thresholds that would trigger rollback.