System Design Lab›System Design Questions›Design Live Comments

Design Live Comments

MediumReal-time Systemsreal-timewebsocketsmessagingrate-limiting🟣 Meta

Question Overview

Design live comments for a live-video platform, where every viewer of a broadcast sees new comments within seconds. The hard parts are routing comments only to the right connections, holding tens of millions of persistent connections, and keeping a stream with millions of viewers readable and stable.…

Sign up to see the full question and AI interviewer

Requirements

  • Post a comment on a live video and have it appear for other viewers within 2 seconds at p95
  • Viewers joining mid-stream see the most recent comments at once, then new ones live
  • Broadcasters and moderators delete comments and ban users, with removals propagated to connected viewers
  • Per-user rate limits and spam filtering on the write path
  • Stay stable when one stream has 5M concurrent viewers; sampling comments on busy streams is acceptable
  • Acknowledged comments are durably stored for replay; the live feed favors availability over strict ordering

Back-of-the-envelope numbers

  • Comment writes: 10K/s at peak, ~4K/s average × 86,400 s ≈ 350M comments/day × 300 B ≈ 100 GB/day ≈ 38 TB/year
  • Naive hot-stream fan-out: 2K comments/s × 5M viewers = 10B deliveries/s, impossible to push and unreadable by any human
  • Sampled hot stream: cap at 10 comments/s per viewer, batched into 2 frames/s of ~1.5 KB → 5M × 2 = 10M frames/s ≈ 15 GB/s (120 Gbps)
  • Connections: 50M concurrent WebSocket or SSE connections ÷ ~100K per gateway host ≈ 500 hosts, ~1,000 with failover headroom
  • Pub/sub fan-out: the hot stream's viewers sit on at most ~1,000 gateways, so each comment batch is published ≤ 1,000 times, not 5M times
  • Join backfill cache: last 50 comments × 1M live streams × 300 B ≈ 15 GB, easily held in a Redis cluster

Key components

  • Comment service that validates, rate-limits per user, runs spam and profanity checks, persists the comment, then publishes it to the video's channel
  • Pub/sub layer with one channel per live video, so each comment is routed only to gateways that have viewers of that video
  • Real-time gateways holding WebSocket or SSE connections, with an in-memory map of video_id to local connections for last-mile fan-out
  • Batching and sampling on hot streams: gateways flush every ~500 ms and cap comments per viewer, favoring friends, verified accounts, and highlighted comments
  • Recent-comments cache: a capped list per video in Redis that serves the last 50 comments to viewers joining mid-stream
  • Moderation events such as deletes and bans flow through the same channels as tombstones so clients remove comments already on screen
  • Durable comment store (e.g. Cassandra keyed by video_id and time bucket) that also powers replay against the recording's timestamps

Common mistakes

  • Having clients poll the database for new comments every second, turning 50M viewers into 50M mostly empty queries per second
  • Pushing every comment to every viewer of a hot stream: 2K comments/s × 5M viewers is 10B messages/s, far beyond what anyone can read
  • Broadcasting every comment to every gateway instead of routing by video subscription, so each gateway processes all 10K comments/s
  • Requiring strict global ordering or strong consistency for comments, adding latency to a feature that tolerates approximate order
  • Letting sampling hide a viewer's own comment; the author should always see it immediately through a local echo
  • Pinning each video to a single server for all writes and fan-out, so one hot stream overloads one machine

Likely follow-ups

  • How would you choose which comments to show when a stream receives thousands per second?
  • How would you replay comments in sync with the recorded video after the broadcast ends?
  • What happens to viewers when a gateway server crashes, and how do they reconnect without missing comments?
  • How would you add reactions such as hearts, which arrive at many times the comment rate?
  • How would you serve viewers of the same stream spread across several regions?
  • How would you shadow-ban a spammer so they still see their own comments but nobody else does?

No community solutions yet

Be the first to publish your solution

Practice ‘Design Live Comments’ with an AI Interviewer

Get scored feedback on your diagram, scalability approach, and trade-offs. Free while we grow — up to 3 full interviews a day.