The whole course ▾

System Design · Mock interview 13 of 20

Design live comments for a stream

Updated 22 Oct 2026 · By Akshay, software engineer, India · 9 min read

Design live comments for a live video stream.

Try it first

Before you read the interview, answer the question yourself. Give yourself 10 minutes: say your design out loud, or sketch it on paper. What would you ask? Which numbers matter? Which boxes, and what's the hard part? Then read on, and score yourself with the feedback at the end.

The video for this mock interview is coming soon.

New System Design videos go up at 6 pm. Subscribe on YouTube so you don't miss it.

Got a doubt? Ask in the comments under the video.Subscribe

Requirements

Requirements
Clarifying questions
->
Scale? -> 5M viewers on one stream
->
Comment rate? -> Up to 10,000 a second
->
See every comment? -> No, a readable stream
->
Delay? -> Under two seconds
Functional requirements
Post a comment
See a live stream of comments
Your own comment appears instantly
Moderation: filter, delete, ban
Non-functional requirements
->
On screen within 2 seconds
->
5M connections held open
->
Calm under sudden spikes
->
Abuse removed within seconds
Out of scope
Replaying old comments
Emoji reactions
The video itself
interviewer
Hi. Let's dive in.
candidate
Sure. I'll draw as I go.
interviewer
Design live comments for a live video stream, like the comment feed beside a big cricket match. Viewers post comments, and everyone watching sees them scroll past.
candidate
Okay. That sounds like a chat room, but at a big match it's probably a different problem. Let me ask a few questions.
interviewer
Go ahead.
candidate
What scale?
interviewer
Up to five million viewers on a single stream, for a final.
candidate
What's the comment rate?
interviewer
Normally a few hundred a second. At a wicket or a six, up to ten thousand.
candidate
Must everyone see every comment?
interviewer
No. Viewers should see a lively, readable stream.
candidate
And the delay?
interviewer
Within about two seconds.
candidate
That third answer helps a lot.
candidate
So, what it does. Post a comment. See a live stream of comments beside the video. See your own comment appear instantly, because posting into silence feels broken. And moderation: filter abuse, delete comments, and ban accounts.
candidate
And how well. Comments on screen within two seconds. Five million connections held open at once. Calm under sudden spikes: a wicket can multiply the comment rate twenty times in a second. And abuse removed within seconds, before five million people see it.
interviewer
Twenty times, in a second?
candidate
Yes. Everyone reacts to the same moment, at the same moment.
candidate
I'll leave out replaying comments with a recording, emoji reactions, and the video itself. Does that match what you had in mind?
interviewer
Yes. Comments only.

Estimation

Estimation
Back of the envelope
Peak: 10,000 comments a second
× 5M viewers = 50B deliveries/s
A person reads ~5 comments a second
5M ÷ 50,000 per server = 100 servers
WHAT THE NUMBERS DECIDE
Nobodycanread10,000
commentsasecond:sendeach
viewerasample,andfanout
batches,notsinglecomments.
candidate
Let me do the numbers. I suspect one multiplication changes everything.
interviewer
What load are we looking at?
candidate
Comments, times viewers.
candidate
At the peak, ten thousand comments a second. If every comment went to every one of five million viewers, that's fifty billion deliveries a second. Impossible, and pointless, because a person reads maybe five comments a second at most. And to hold the connections, at about fifty thousand sockets per server, five million viewers need around a hundred servers.
interviewer
And a normal match?
candidate
A few hundred comments a second. The design has to handle both, without anyone switching modes.
candidate
So nobody can read ten thousand comments a second, and I shouldn't try to deliver them. Each viewer gets a sample, a readable stream of maybe ten a second. And the same sample goes to everyone, in small batches, so the fan-out is a few messages a second per viewer, not ten thousand.
interviewer
That's exactly the insight I was hoping for.

API and data

API and data
Comments
stream, time, user,
text, status
Comment
topic
Kafka, per
stream
stored for
moderation
Endpoints
1
POST /streams/{id}/comments
2
WebSocket: /streams/{id}/live
3
<- a batch of comments, every
~0.5 s
4
<- delete events, from moderators
candidate
Next, the API. One way in, one way out.
interviewer
What does the API look like?
candidate
Posting is an ordinary request. Watching is a long-lived connection.
candidate
POST a comment to a stream, an ordinary request with the text. To watch, the app opens a WebSocket, a live socket to the stream's channel. Down it comes a batch of comments about twice a second, already sampled and ready to show. And delete events, when a moderator removes a comment that's already on screens.
interviewer
Why batch?
candidate
Two messages a second instead of hundreds saves battery and data on phones.
candidate
Every comment is stored in a comments table, keyed by stream and time, in a write-heavy store like Cassandra, because ten thousand writes a second arrive in bursts, and they're read rarely, by moderators and for reports. And every comment also flows through a comment topic in Kafka, which is where the live path begins.
interviewer
Why Kafka in the middle?
candidate
So moderation, analytics and the live path can all read the same comments, independently.

High-level design

High-level design
Fan's
phone
Comment
service
rate
limits,
filters
Kafka
comments
for
stream
7
Sampler
picks ~10
a second
POST
comment
1
accepted
2
3
Pub/sub
channel:
stream
7
Connection
servers
50,000
sockets
each
Five million
viewers
one batch
4
to ~100
servers
5
same batch
to all
6
TWO RISKS
Fan-outmuststayflat
whencommentsspike.And
abusemustbestopped
beforemillionsseeit.
interviewer
Okay. Let's follow a comment.
interviewer
Walk me through one comment, from posting to every screen.
candidate
The way in first, then the way out.
candidate
A fan's phone posts a comment. The comment service checks the user's rate limit, say one comment every two seconds, runs a fast abuse filter, and publishes the comment to Kafka. The fan's own app shows their comment immediately, without waiting for any of this. Then a sampler, one per stream, reads every comment and picks about ten a second to show, packing them into a batch every half second.
interviewer
Why one sampler per stream?
candidate
Each stream's audience sees its own sample, and one stream's spike shouldn't touch another's.
candidate
The sampler publishes each batch once, to the stream's channel on pub/sub. About a hundred connection servers are subscribed, one message each. Every connection server then writes that same batch down its fifty thousand open sockets. So one batch becomes a hundred messages, then five million socket writes: a broadcast tree. And all five million viewers see the same stream within a second or two.
interviewer
Does that work for a small stream too?
candidate
The same tree. Only the number of connection servers changes.
interviewer
What would you worry about?
candidate
Two things. When a wicket falls and comments jump twenty times, the fan-out has to stay flat. And abuse has to be stopped, or removed, before five million people read it.
interviewer
Fan-out first.

Deep dive: fan-out at scale

Deep dive: fan-out at scale
Every comment to everyone
10,000 × 5M deliveries a second
Grows with every new comment
Unreadable on screen anyway
Sampled batches, broadcast
~2 batches a second per viewer
Flat, however fast comments come
A readable, lively stream
THE CHOICE
Asamplerperstream,batches
twiceasecond,andabroadcast
treethroughpub/suband
connectionservers.
High-level design
Fan's
phone
Comment
service
rate
limits,
filters
Kafka
comments
for
stream
7
Sampler
picks ~10
a second
POST
comment
1
accepted
2
3
Pub/sub
channel:
stream
7
Connection
servers
50,000
sockets
each
Five million
viewers
one batch
4
to ~100
servers
5
same batch
to all
6
10,000/s in, 10/s out
absorbs the spike
TWO RISKS
Fan-outmuststayflat
whencommentsspike.And
abusemustbestopped
beforemillionsseeit.
interviewer
Let's go deeper on the fan-out.
interviewer
Why not just push every comment to every viewer?
candidate
Let me compare the two out loud.
candidate
Pushing every comment to everyone means ten thousand times five million deliveries a second, a load that grows with every extra comment, to produce a screen that scrolls too fast to read. Sampled batches mean about two messages a second per viewer, flat no matter how fast comments arrive, and a stream people can actually read. The second does far less work, and it's a better product.
interviewer
How do you choose which comments to show?
candidate
Not purely at random. Comments from people the viewer follows, from verified accounts, and ones getting replies, then the rest at random. And the sampler keeps the number shown per second steady: lively when the match is slow, readable when it's frantic.
candidate
So when a wicket falls, and comments jump from five hundred a second to ten thousand, Kafka absorbs the spike. The sampler reads faster, but still sends ten a second. Everything after the sampler, pub/sub, the connection servers, five million sockets, sees exactly the same load as before.
interviewer
What if Kafka itself is overwhelmed?
candidate
Ten thousand small messages a second is light for Kafka. And the comment service can turn away posts above a ceiling, which viewers barely notice.
interviewer
Can one sampler keep up with ten thousand comments a second?
candidate
For one stream, easily, since it's only choosing, not storing. For safety, I'd split the stream's topic into partitions, run a sampler per partition, and let a small merger combine their picks.
interviewer
Good.
interviewer
What if a connection server falls behind, because some viewers are on slow networks?
candidate
One slow viewer must never hold up the others. Each socket gets a small outgoing buffer, and if a viewer can't keep up, the server drops older batches for that viewer and sends only the newest. Missing a few comments is fine. Falling a minute behind the match is not.

Deep dive: connections and abuse

Deep dive: connections and abuse
Holding millions of sockets
1
Scale up before the scheduled start
2
Spread connections by least load
3
Reconnect with random delays
4
Servers near viewers, in each region
Keeping it clean
->
Filter before Kafka: words, links, spam
->
Slow mode: one comment per 10 s
->
Delete: a remove event to all screens
interviewer
Now, connections and abuse.
interviewer
Five million people open the stream in the minute before the match. What happens to the connection servers?
candidate
If I plan for it, nothing dramatic.
candidate
A final is scheduled, so I'd add connection servers before kick-off, not during it. The load balancer sends new sockets to the servers with the least connections. If a server dies, its fifty thousand viewers reconnect after a random delay, so they don't all arrive in the same second. And connection servers sit in each region, near viewers, so a batch crosses the world once.
interviewer
How can one server hold fifty thousand?
candidate
Most viewers are idle most of the time, just listening.
candidate
Moderation works in layers. A fast filter runs before a comment even reaches Kafka: blocked words, links, repeated spam, and a model scoring abuse, in milliseconds. In a heated moment, moderators can switch on slow mode: one comment per person every ten seconds. And when a moderator deletes a comment that's already out, a remove event travels the same broadcast tree, and every app takes it off the screen.
interviewer
Doesn't the filter slow down posting?
candidate
By a few milliseconds. Worth it, since a comment on millions of screens can't be taken back.
interviewer
A troll posts from a thousand fresh accounts. Then what?
candidate
New accounts can be held back from the sample until they have some history, without being told, so their comments only show to themselves. Repeated text across accounts is caught by the filter. And since only ten comments a second are shown, the sampler can simply prefer trusted accounts.
interviewer
So sampling is moderation too.
candidate
Exactly.
interviewer
Where is each comment stored, and for how long?
candidate
Every accepted comment goes to the comments store, even ones never shown, because moderators, reports and legal requests may need them. After the stream, they move to cheaper storage, and are deleted after a fixed period. The live path never reads from that store at all.

Wrap-up

Wrap-up
Next steps
1
Reactions: counts, merged per second
2
Replay comments with the recording
3
Watch delay, sample rate, dropped sockets
4
Better ranking of shown comments
INTERVIEWER'S FEEDBACK
Strong:thesamplinginsight,abatched
broadcast,socketsscaledbeforekick-off,
layeredmoderation.Nexttime:whatifthe
samplerdies?Verdict:stronghire.
interviewer
We're nearly at time.
interviewer
What would you improve with more time?
candidate
A few things.
candidate
First, emoji reactions: counted per second, and sent as one small update, not millions of events. Second, replay comments alongside the recording, read from the store by time. Third, I'd watch the delay from post to screen, the sample rate, and dropped connections. And fourth, smarter ranking of which comments are shown, so the best ones surface.
interviewer
Which would you do first?
candidate
The watching. The delay from post to screen is the promise we made.
interviewer
Okay, let's stop there. Excellent. You found the key insight in the estimate: nobody can read ten thousand comments a second, so viewers get a sample. The batched broadcast keeps the fan-out flat in a spike, you scaled the sockets before kick-off, and moderation works in layers. One gap: what happens if the sampler itself dies mid-match. I'd say a strong hire.
candidate
Thanks. A standby sampler, reading the same topic, would take over.
Interviewer's feedback

Strong: the sampling insight, a batched broadcast, sockets scaled before kick-off, layered moderation. Next time: what if the sampler dies? Verdict: strong hire.

Score yourself

Interviewers score these seven things. Give your own attempt a tick for each one you did.

  • Asks before drawing. Agrees what the system does, and how well: scale, speed, consistency.
  • Turns users into requests a second and bytes a day, and says what the numbers decide.
  • A small, clear contract, and a data model that fits how the data is read.
  • A working path end to end before any detail. Every box has a reason.
  • Picks the hard parts, compares two options, and chooses one with a trade-off said out loud.
  • What breaks, what happens then, and how users notice. Retries, duplicates, limits.
  • Thinks out loud, checks in with the interviewer, and takes a hint without losing the thread.

0 of 7

Your progress stays on this device.
New System Design videos at 6 pm

Lessons on weekdays, the week's revision on Saturday, a mock interview on Sunday.