Skip to content

Design Live Comments

A system design interview walkthrough for live comments on a stream: fan-out to a million viewers, SSE vs WebSocket, sampling and moderation.

Intermediate22 minUpdated 2 December 2026

Before this: API Paradigms: REST vs GraphQL vs gRPC, Caching, Message Queues

"Design live comments" is the question behind the scrolling chat beside a live video or a breaking-news post. Each comment is tiny and the write rate is modest. The difficulty is that one popular video can have a million people watching it at once, and every one of them wants to see the new comments within a second or two.

The interviewer is testing whether you notice that this is a fan-out problem with an unusual shape: one writer population, a huge, very uneven reader population, and a hard physical limit on how many comments a human can read. Do you reach for the right transport? Do you keep the comment service out of the connection business? And do you realize that sending every comment to every viewer is neither affordable nor useful?

This page is about delivering a stream of comments for one piece of content. Two-way chat and direct messages are covered in Design WhatsApp, and the feed-style fan-out of posts to followers is in Design Instagram.

Clarify the requirements

Functional requirements:

  1. A signed-in viewer posts a comment on a live video or post.
  2. Everyone watching sees new comments appear within a couple of seconds.
  3. A viewer who joins late sees recent comments, and can load older ones.
  4. Pin a comment, and delete one (by the author, the host or a moderator).
  5. Show a running comment count.

Out of scope, said aloud: threaded replies, reactions and emoji bursts (mention them as a follow-up), comment search, translation.

Non-functional requirements: these decide the architecture.

  • Delivery in about two seconds is enough. Comments are not a conversation between two people, so there is no need for 100 ms.
  • Availability over exactness. Seeing most comments is fine. Losing a few in a flood is acceptable. Taking the video page down because comments failed is not.
  • A million concurrent viewers on one video, and a very long tail of videos with ten viewers. The design must not be sized for the average.
  • Moderation before display. Spam and abuse must be filtered quickly, and a deleted comment must disappear from screens that already have it.
  • Isolation. Comments are a side feature. A comment flood must never degrade video playback.

Estimate the scale

Assume 50 million daily users of the feature. Each posts about 2 comments a day, and each receives about 200 comments a day across the videos they watch.

Writes: 50M × 2 = 100 million comments a day, or 100M ÷ 86,400 ≈ 1,200 per second on average.

Reads (deliveries): 50M × 200 = 10 billion a day, about 116,000 per second on average. The average hides the real shape.

The hot event: one viral live video with 1 million concurrent viewers and 20,000 comments per second arriving. If we sent every comment to every viewer, that would be 1M × 20,000 = 20 billion pushes per second. Impossible, and also pointless, since no one can read 20,000 lines a second.

After sampling: show each viewer about 5 comments a second. Pushes are 1M × 5 = 5 million per second. At about 200 bytes per comment, that is 1 GB/s, or 8 Gbps, of outbound traffic for one video.

Connections: with 100,000 connections per relay host, a 1M-viewer video needs 10 relay hosts, each sending about 100,000 × 5 × 200 B = 100 MB/s (800 Mbps).

Storage: 100M comments × 300 B ≈ 30 GB a day, about 11 TB a year.

"Average load is small. One event is not. The write path is a few thousand inserts a second at most. The real problem is a single video with a million viewers, so the design has to stop sending every comment to every viewer and has to hold a million connections without the comment service holding them."

The capacity estimator reproduces the daily totals and the yearly storage. The hot event you size by hand.

API and data model

Posting is an ordinary request. Receiving is a long-lived stream.

POST   /v1/videos/{id}/comments         { clientId, text }          -> 202 { commentId }
DELETE /v1/comments/{commentId}
GET    /v1/videos/{id}/comments?before=<cursor>&limit=50           -> older page
GET    /v1/videos/{id}/stream?since=<cursor>                       -> text/event-stream
comments  (video_id PK, comment_id CK  [time-ordered ID], user_id, text, state)
counters  (video_id PK, count)
recent    Redis list per video: last 200 comments (capped)

The non-obvious choice: the recent list lives in Redis, capped at the last few hundred comments, because nearly every read is "what are the latest comments on this video". The durable table is for paging backward and for audit, and is rarely touched on the hot path.

High-level design

We simulate the core of it: viewers connect to a relay tier that holds the connections, a comment service accepts and filters posts, a Redis list serves recent comments to people who join, and a durable store keeps the history.

Viewers connect through a WebSocket relay tier to a comment service, which keeps recent comments in Redis and the full history in Cassandra.viewerscomment relaycomment servicerecent commentscomment store
Viewers connect through a WebSocket relay tier to a comment service, which keeps recent comments in Redis and the full history in Cassandra.
  • The relay tier holds the viewer connections, so the comment service never does.
  • The service serves recent comments from Redis and appends every comment to the durable store.
Describe this diagram

Components

  • viewers (Client)
  • comment relay (WebSocket gateway)
  • comment service (Service)
  • recent comments (Redis)
  • comment store (Cassandra)

Connections

  • viewers sends to comment relay
  • comment relay sends to comment service
  • comment service sends to recent comments
  • comment service sends to comment store

Run it, then try shrinking the relay tier or raising the share of writes. Connection capacity runs out well before storage does.

The write path: the service authenticates the user, rate-limits them, runs a fast spam check, assigns a time-ordered comment ID, writes to the durable store and the capped Redis list, and publishes the comment to that video's channel. The poster gets 202 right away.

The read path for a new viewer: fetch the capped recent list from Redis (one round trip), then open the stream with since=<last comment ID>. Older pages come from the durable store by cursor.

The interesting problem: reaching a million viewers

The comment must travel from one service to a million screens. There are three families of answer.

Approach A: short polling with a cursor

Each client asks GET /comments?since=<id> every two seconds.

Good: works on any network and any proxy, needs no connection fleet, and the response for "comments since cursor X in this two-second window" is identical for every viewer, so a CDN or cache can answer almost all of it. This is the same trick as live video segments in a CDN.

Bad: 1M viewers polling every 2 s is 500,000 requests per second, and latency averages one second plus the cache time. Most polls return little.

Approach B: the comment service pushes to every viewer

Every viewer holds a WebSocket to the service, and the service writes to each.

Good: lowest latency, simplest to explain.

Bad: the service that validates and stores comments now also holds a million sockets and does a million writes per comment batch. A slow client stalls a writer. Scaling the service for connections scales the wrong thing, and a connection storm takes down posting too.

Approach C: a relay tier with one subscription per video per relay

Separate the two jobs. The comment service publishes each accepted comment once to a pub/sub channel for the video. A fleet of relay hosts holds the viewer connections. Each relay subscribes to a video's channel once, no matter how many local viewers watch it, and fans out to those viewers locally, in memory.

Good: the comment service sees one publish per comment. The pub/sub system sees one delivery per relay per comment (10 relays, not 1M viewers). Connections are the relay's only job, and it can be scaled, drained and replaced independently.

Bad: more moving parts, and each relay needs backpressure so a slow client is dropped or skipped rather than buffered forever.

The recommended answer is C, plus sampling at the relay: each relay collects the video's comments for 500 ms, picks a sample (priority to pinned comments, the host's comments and replies, then a fair random sample of the rest) and sends one batch per viewer. Viewers see a readable stream, and bandwidth stops growing with the comment rate.

Choosing the transport: SSE or WebSocket

Comments mostly flow one way, server to client. Posting is a separate POST. That makes Server-Sent Events a natural fit: it is plain HTTP, reconnects automatically, resumes with a Last-Event-ID header and passes through most proxies and load balancers. A WebSocket gives a duplex channel you do not need here, and brings its own upgrade handshake and heartbeats to manage.

Choose WebSocket when you add features that need fast client-to-server messages, such as typing indicators or live reactions, as in Design WhatsApp. Say that you would start with SSE and change if the product demands duplex. See API styles for the wider comparison.

Either way, build resumption in: every comment carries a time-ordered ID, and a reconnecting client sends the last one it saw. The relay or cache replays from the capped recent list, and the client skips any duplicates.

Bottlenecks and failures

A relay host dies. Its 100,000 viewers reconnect to other relays at once. Use jittered backoff, a per-relay connection cap, and resume from the last comment ID so nobody sees a gap.

A slow client. A phone on a bad connection cannot keep up with the stream. Give each connection a small bounded buffer and, when it fills, drop the oldest queued comments. Never let one slow reader grow memory or hold up others.

A comment flood or spam attack. Rate-limit per user and per IP at the comment service, run cheap checks first (length, links, repeated text) and a heavier classifier asynchronously. A shadow-banned author's comments are stored and shown only to them. This is the same defensive approach as in rate limiting.

What if the pub/sub layer is down? Viewers stop receiving live comments, but posting still stores them. Relays can fall back to polling the Redis list every second, and the video is unaffected. Comments are a feature to degrade, never one to fail with.

Trade-offs to name aloud

  • Sampling over completeness: viewers see a readable subset of a flood, in exchange for bandwidth that stays flat as the comment rate grows.
  • Relay tier over direct push: more components, in exchange for keeping connections away from the service that must stay healthy to accept posts.
  • SSE over WebSocket: simpler and proxy-friendly, with no duplex channel for typing or reactions until needed.

What interviewers listen for

  • A working answer: a comment service, a database, and a way to push new comments to viewers over WebSocket or polling.
  • A strong answer: sizes the hot event rather than the average, separates connection handling from the comment service, publishes once per video and lets relays fan out locally, and supports resuming from the last ID.
  • A standout answer: also samples comments to a human-readable rate and computes the bandwidth saving, picks SSE with a clear reason, handles slow clients with bounded buffers, deletes and moderation as events, and degrades gracefully when the live path is down.

Check your understanding

Common mistakes

Pushing everything, to everyone. Even with infinite bandwidth, a screen cannot show 20,000 lines a second. Sampling is a product decision that also happens to fix the cost.

Forgetting resumption. Mobile connections drop constantly. Without an ID to resume from, every reconnect loses or duplicates comments.

Unbounded per-connection buffers. One slow client can exhaust a relay's memory. Always drop or skip when the buffer fills.

Treating moderation as an afterthought. A live stream with open comments gets abuse within minutes. Say where the rate limit, the cheap filter, the asynchronous classifier and the delete event sit.

Practice

A relay host with 100,000 viewers crashes during a big event. Describe what the viewers experience and how your design keeps it from becoming a second outage.

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Think about where the 100,000 reconnects go, what they ask for, and what each one costs.

Show a strong answer

Reconnects arrive together. Without a plan, 100,000 clients retry within seconds and hit the remaining relays, which also hold 100,000 each. Clients use exponential backoff with random jitter over 30 to 60 seconds, so arrivals spread to about 2,000 a second, which is cheap.

Resume from the cursor, not from scratch. Each client sends since=<last comment ID>. The new relay replays from the capped recent list in Redis (one range read per client, cached per video), so nobody refetches a whole page, and nobody sees a gap.

The pattern worth keeping: a failure that disconnects many clients at once is a thundering herd, so design backoff, headroom and cheap resume as part of the first version.

The host of a stream wants comments to appear only after approval, for a high-stakes live event. What changes and what does it cost?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Ask where the approval step sits in the write path and what it does to the two-second target.

Show a strong answer

Add a state to the comment. A comment is pending after posting and becomes visible on approval. Only visible comments are published to the video's channel and added to the recent list. The poster sees their own pending comment locally, with a note.

Put approval on the publish edge. The comment service writes the row as pending and queues it for a moderator tool, which could be a human queue plus an automated classifier that approves the clearly safe ones. Approval calls the same publish step the normal path uses.

The cost is latency and moderator load. Comments no longer appear in two seconds, so say so and set the product expectation. At 20,000 comments a second no human queue can keep up, so you would combine the classifier with sampling, and approve first the comments from verified or previously approved authors.

The pattern worth keeping: a policy like moderation is a state transition before the publish step, not a change to the delivery path.

Key takeaways

  • The problem is one hot video, not the average. Size the 1M-viewer event.
  • Separate connections from the comment service: a relay tier subscribes to each video once and fans out locally.
  • Sample the stream to a readable rate and bound bandwidth: 5 comments a second times 1M viewers is 1 GB/s.
  • SSE is a good default for one-way push. Choose WebSocket only for duplex needs.
  • Resume from a cursor, bound per-client buffers, and use jittered reconnects.
  • Degrade comments before video: comments are a feature that can fail soft.

Further reading

  • WHATWG, "HTML Living Standard", the section on server-sent events: the EventSource API, reconnection and Last-Event-ID.
  • I. Fette and A. Melnikov, RFC 6455 "The WebSocket Protocol" (2011): when a duplex channel is worth its complexity.
  • J. Kreps, N. Narkhede and J. Rao, "Kafka: a Distributed Messaging System for Log Processing", NetDB workshop (2011): publish-subscribe at high fan-in.

Check yourself

3 questions in this lesson. Answer each once to complete it.

Practice this

Lessons in this track