KatInterview

Real-Time Chat for Mass-Audience Livestreams

System DesignModel answer
MediumModel answerSystem Designfan-outwebsocketkafka

Last updated

Design a chat feed for livestreams where one broadcast may have over a million viewers, with sub-half-second delivery, durable storage and live moderation.

Scenario

You are building the chat feature for a livestreaming product. During a popular broadcast, viewers type short messages that everyone else watching sees scroll by in near real time. A single stream can attract hundreds of thousands to over a million simultaneous viewers, and traffic can jump sharply when a well-known streamer goes live.

What the system must do

  • A viewer can send a chat message to a stream they are watching.
  • Every viewer sees a continuously updating feed of messages from the stream.
  • The system absorbs a very large number of people posting at once.

Quality targets

  • Speed: a message should reach viewers in under 500 ms.
  • Scale: at least 100k simultaneous viewers on one stream, with room to grow beyond that.
  • Durability vs. freshness: every accepted message must eventually be stored, but it is acceptable for a live viewer to miss an occasional update.

What you should cover

  1. A high-level architecture, and how its components interact.
  2. The API surface (WebSocket and/or REST).
  3. A data model for storing messages.
  4. How you deliver each message to a huge audience (the fan-out problem).
  5. How you moderate content in real time.

State your assumptions about traffic numbers and justify the trade-offs you make.

Hints

Hint 1

Multiply write rate by audience size. If 10k messages per second must each go to 1M viewers, the raw delivery count is absurd. Ask what a human can actually read, and what that implies for how much you send each viewer.

Hint 2

Separate the write path (accept, validate, make durable) from the delivery path (push to live viewers). Durability can be settled once the message is in a replicated log, without waiting on the database or on any viewer.

Hint 3

Fan-out should be a tree: one pub/sub publish reaches a modest number of edge gateways, and each gateway holds many sockets and does batching, sampling and per-viewer filtering locally.

Hint 4

Moderation should be layered: very cheap synchronous checks before accepting, slower ML or human review afterward, with a way to retract a message that has already been shown.