System design interview: design live comments

Live comments let viewers of a live video post messages that every other viewer sees within a second or two. The design problem is fan-out to a crowd: a popular stream can have millions of viewers and thousands of comments a second, so you route each comment once per connection server rather than once per viewer, batch what you push, and show each viewer a sample rather than every message.

By Published 7 min read

1. Clarify the requirements

This prompt sits between chat and a feed. Confirm which parts matter: reach, latency, order or history.

  • Functional: a viewer posts a short text comment on a live stream; every viewer of that stream sees new comments while watching; a new viewer sees the most recent few dozen; the streamer and moderators can delete comments and block users; comments replay with the recording afterwards.
  • Non-functional: a comment appears for others in about one to two seconds; the system survives a stream that suddenly gets millions of viewers; comments are not lost once accepted, but a viewer does not need to see every one on a busy stream.
  • Out of scope unless asked: the video pipeline, direct messages, paid highlighted comments (mention them as a priority lane later).

2. Estimate the scale

Numbers for a large live video platform (assumed figures)
QuantityAssumptionResult
Hot stream2 million concurrent viewers, 2,000 comments a secondpushing every comment to everyone = 4 billion messages a second: impossible
Same stream, batchedone batch every 500 ms per viewer4 million pushes a second, spread over the gateways
Gateways for that streamabout 100,000 connections per gatewayabout 20 gateways hold its viewers
Pub/sub traffic for that streamone message per comment per subscribed gateway2,000 x 20 = 40,000 messages a second, and less with batching at the source
Platform write ratepeak 100,000 comments a second across all streams, average a quarter of thatabout 25,000 writes a second sustained
Storageabout 300 bytes per comment with metadataabout 650 GB a day at the average rate
Numbers for a large live video platform (assumed figures). Scroll sideways on a small screen.

The first row is the reason the question exists. Writes and storage are ordinary; the delivery multiplier is what you design around.

3. Define the API

POST /v1/streams/{stream_id}/comments   { text, client_msg_id }
  -> 201 { comment_id, ts }

GET  /v1/streams/{stream_id}/comments/recent?limit=50   (on join)

WS   /v1/streams/{stream_id}/live
  server -> client  { type: "batch", comments: [ { id, user, text, ts } ], dropped: 1430 }
  server -> client  { type: "delete", comment_id }
Posting is a plain request; receiving is a long-lived stream.

Posting over plain HTTP keeps writes on a simple, rate-limitable path. client_msg_id makes retries safe, and the dropped count lets the app show that the chat is moving faster than the screen.

4. Sketch the data model

Comment storage and live state
DataStore and keyNotes
CommentsWide-column store, partition (stream_id, 10-minute bucket), clustered by tsTime buckets stop one hot stream from building a giant partition
Recent commentsCapped list per stream in an in-memory cache, last 100 or soServes the join request without touching the store
Stream subscriptionsPub/sub channel per stream, subscribers are gatewaysIn memory only
Bans and blocked wordsPer stream and global lists, cached in the comment serviceRead on every post
Comment storage and live state. Scroll sideways on a small screen.

5. The core idea: two-level fan-out

  1. AcceptThe comment service authenticates the poster, applies a per-user rate limit and the fast moderation checks, assigns an ID and timestamp, writes the comment to the store and the recent list.
  2. Publish onceIt publishes the comment to the stream's channel. Only gateways with at least one viewer of that stream are subscribed, so a comment reaches each relevant gateway once.
  3. Batch per gatewayEach gateway buffers comments per stream and every 500 ms builds one batch, sampling down to a cap (say 20 comments) when the stream is busy.
  4. Deliver locallyThe gateway writes that same batch to every local viewer's connection. One serialisation, many socket writes, no further network hops.

The first level (comment to gateways) scales with the number of gateways, not viewers. The second level (gateway to viewers) is local and parallel. This is the same idea as subscribing connection servers to a user's channel in nearby friends, applied to a crowd instead of a friend list.

How to sample. Keep comments from the streamer and moderators, replies to the viewer, and the viewer's own posts. Fill the rest of the cap with a random or recency-weighted sample. Two viewers seeing slightly different comment lists is normal on busy streams and nobody notices.

6. The architecture

  1. Viewers
    • App and web players
  2. Write path
    • Load balancer
    • Comment service (rate limit, fast checks)
  3. Storage
    • Comment store by stream and time bucket
    • Recent comments cache
  4. Delivery
    • Pub/sub cluster, channel per stream
    • Gateway servers (batch and sample)
  5. Safety
    • Async moderation pipeline
    • Delete events
Write path and delivery path for live comments. Viewers post comments over HTTP through a load balancer to a comment service, which rate-limits, runs fast moderation, writes to a partitioned comment store and a recent-comments cache, and publishes to the stream's channel on a pub/sub cluster. Gateway servers that hold viewers of the stream are subscribed to its channel; each batches incoming comments every few hundred milliseconds and pushes the batch to its local viewers over WebSockets. A slower moderation pipeline consumes the comment stream and emits delete events through the same channel.

7. Deep dives

  • Hot channel. One stream's channel can overload a single pub/sub node. Split it into a few sub-channels by comment ID and have gateways subscribe to all of them, or let the comment service pre-batch every 100 ms so the channel carries batches rather than single comments.
  • Viewers spread over many gateways. If a hot stream's viewers sit on every gateway, each gateway subscribes. Routing viewers of a hot stream to a subset of gateways (by stream ID in the load balancer) reduces subscriptions, at the cost of less even load.
  • Ordering. Viewers need comments roughly in time order, not a strict global sequence. Sort each batch by server timestamp; a comment that arrives a little late goes into the next batch.
  • Join and reconnect. A new or reconnecting viewer loads the recent list once, then follows the socket. Skip the gap rather than replaying it; on a live stream nobody scrolls back through two thousand missed comments.
  • Replay with the recording. Store each comment's offset from the stream start. The video player fetches comments for the next few minutes of playback as it goes, which is a simple range read on the time-bucketed partition.
  • Rate limits. Per user per stream (a few comments a minute in slow mode) and per stream overall. The algorithms are in design a rate limiter.

8. What breaks, and what you do about it

Failure modes
FailureEffectMitigation
Gateway crashesIts viewers lose the comment feedClients reconnect with jitter to another gateway, load recent comments, resume; video playback is unaffected
Pub/sub node failsStreams on it go quiet for a momentReplicas or remapping; comments are already stored, so recent lists stay correct
Spam waveFeed fills with junkPer-user limits, slow mode switched on automatically above a threshold, fast blocked-word filter
Comment store slowPosting latency climbsPublish to the channel after a successful write to the recent list, persist through a queue, and alert
Comment deleted after displaySome viewers already saw itSend a delete event so clients remove it; keep slow checks fast enough that this stays rare
Failure modes. Scroll sideways on a small screen.

9. Trade-offs to discuss

  • Completeness or readability. Delivering everything is costly and unreadable; sampling is cheap and readable but means viewers see different things. Most products choose sampling on busy streams and full delivery on small ones.
  • WebSockets or server-sent events. Comments flow mostly one way, so server-sent events over HTTP would work and pass through proxies easily; WebSockets suit apps that also send reactions or typing signals on the same connection.
  • Write-then-publish or publish-then-write. Writing first means nothing shown is ever lost; publishing first trims latency but can show a comment that later fails to save. For comments, a short write to the in-memory recent list is a reasonable middle.
  • Compared with a feed. A notification system must deliver every message to every recipient; live comments trade that for speed and scale.

10. How to talk through it in the interview

Fictional example

Handling a sudden viral stream
Interviewer
A stream goes from a thousand viewers to three million in ten minutes. Walk me through what changes.
Candidate
New viewers land on gateways that may not be subscribed yet, so each subscribes to the stream's channel on first viewer. Pub/sub traffic for the stream grows with the number of gateways, not viewers. As comments pass a threshold, gateways switch to sampling, a fixed number per half second per screen.
Interviewer
And the poster side?
Candidate
Writes are a few thousand a second, which the comment service and store handle. I would turn on slow mode automatically for that stream, because spam scales with the audience, and split its channel into sub-channels if one pub/sub node gets hot.
  • Do the naive multiplication out loud; it makes the batching and sampling look necessary rather than clever.
  • Name the two levels of fan-out and where each one runs.
  • Mention moderation and deletion; interviewers often ask about them last.

Practicing this design with Natively

When rehearsing, the useful habit is stating the numbers before the architecture. Hold a mock round on a call with Natively open and it will transcribe what you say, suggest points you skipped when the interviewer asks about a viral stream, and draw the two-level delivery path as a diagram if you ask. The saved notes from the session are a quick way to check whether you ever got to moderation.

Questions people ask

How do live comments work at scale?

Viewers keep a WebSocket or server-sent events connection to gateway servers. A posted comment is stored and published once to the stream's pub/sub channel, each gateway with viewers of that stream receives it once, and the gateway pushes batches to its local viewers every few hundred milliseconds.

How do you handle a live stream with millions of viewers?

Do not send every comment to every viewer. Fan out to gateways rather than viewers, batch on a short timer, and cap each screen to a sample of comments per batch, always keeping the viewer's own posts and moderator messages. Split the stream's channel if one pub/sub node gets hot.

Do live comments need strict ordering?

Usually not. Viewers need comments roughly in time order, so sorting each batch by server timestamp is enough. A strict global sequence would add coordination without a visible benefit.

How are live comments stored?

In a write-friendly store partitioned by stream and a time bucket, clustered by timestamp, so one busy stream does not create a giant partition. A capped in-memory list of recent comments serves viewers who join, and stored offsets let comments replay alongside the recording.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP