In our previous lesson, we built the architectural foundation for a presence system, tackling the challenge of broadcasting ephemeral state like online status and typing indicators at scale. We established the power of push-based architectures using WebSockets and the importance of decoupling services with a message bus like Kafka. Today, we'll apply and extend those principles to one of the most common real-time system design questions you'll face in a senior-level interview: designing a live comments feature, like you'd find on YouTube Live or Facebook Live.
This lesson will guide you through outlining the high-level system for such a feature. We'll start by defining the problem's unique constraints, move from a naive polling approach to a scalable push-based architecture, and finally explore advanced patterns for handling "mega-stream" events with millions of concurrent viewers. The goal is to equip you with a robust, multi-layered answer that demonstrates the architectural thinking expected in a senior or staff-level interview.
1. Defining the Problem: Live Comments at Scale
As always, we begin by clarifying requirements. In an interview, this demonstrates a structured approach and ensures you're solving the right problem. For a live comments system, the stakes are high: millions of users expect to see a seamless, near-instantaneous flow of conversation.
Let's use the excellent breakdown from Hello Interview to frame our problem.
Design Facebook's Live Comments System | Hello Interview System Design in a Hurry
This article provides a clear, interview-focused walkthrough of the live comments design problem.
Start by reading the problem definition section. Pay close attention to the distinction between core functional requirements (posting, real-time viewing, history) and the critical non-functional requirements: scale (millions of users), low latency (<200ms), and prioritizing availability over consistency.
The core challenge is clear: we need to broadcast a high volume of small messages to a massive audience with very low latency. Polling, the simplest approach, breaks down immediately under these constraints. Imagine one million viewers polling every two seconds—that's 500,000 requests per second to your backend, most of which will return no new data. This is incredibly inefficient and fails to meet our latency target. We must adopt a push-based model.
2. Choosing the Right Real-Time Protocol: SSE vs. WebSockets
In the last lesson, we focused on WebSockets. They are a powerful tool for bidirectional communication, perfect for features like chat where the read/write ratio is relatively balanced. However, for live comments, the dynamic is different: viewers are almost exclusively reading comments, with only a small fraction actively writing them. This read/write imbalance suggests we should evaluate our options.
The two primary candidates for a push model are WebSockets and Server-Sent Events (SSE).

As the diagram shows, WebSockets establish a two-way channel, while SSE establishes a one-way channel where the server can push data to the client, but not the other way around. Let's analyze the trade-offs in our context.
Design Facebook's Live Comments System | Hello Interview System Design in a Hurry
This section of the Hello Interview article provides a fantastic comparison of WebSockets and SSE for the live comments use case.
Read the section on real-time broadcasting. Focus on the "Challenges" described for both WebSockets and SSE. The key takeaway is understanding why SSE's unidirectional nature and reliance on standard HTTP make it a simpler, more lightweight, and often better-fitting choice for this specific problem.
To summarize the decision:
- WebSockets: Offer a full-duplex (two-way) connection. This is powerful but introduces complexity. The connection upgrade process can be brittle, especially with older proxies or restrictive firewalls. For a feature where the client-to-server communication is infrequent (posting a comment), maintaining a full WebSocket connection for every one of millions of passive viewers is overkill.
- Server-Sent Events (SSE): Provide a one-way, server-to-client stream over a standard HTTP connection. This is simpler to implement and more robust across different network infrastructures. The client can still post comments using a standard
POSTrequest. This perfectly matches our imbalanced read/write pattern.
Our decision: We will use Server-Sent Events (SSE) for broadcasting new comments to viewers. This choice demonstrates a nuanced understanding of picking the right tool for the job, a hallmark of a senior engineer.
3. Scaling the Real-Time Layer: The Fan-Out Problem
So, we've decided to use SSE. A client establishes an SSE connection to our server and starts receiving comments. This works for one server. But our scale requirement is millions of concurrent viewers. A single server instance can't handle millions of persistent TCP connections. We must scale horizontally by adding more servers.
This introduces a critical coordination problem:
- A user posts a comment via a
POSTrequest, which is handled by Server A. - Viewer 1 is watching the stream and has an SSE connection to Server B.
- Viewer 2 is also watching and is connected to Server C.
How does Server A, which received the comment, tell Servers B and C to push the new comment to their connected clients?
This is the "fan-out" problem. The solution is to decouple the ingestion of comments from the broadcasting of comments using a message bus, a pattern you'll recognize from our previous lesson. Your interest in Kafka and Redis makes this a great area to explore.
System Design Interview: Design Live Comments w/ a Ex-Meta Staff Engineer
This video provides a great visual explanation of the scaling challenge and the two primary solutions: a central dispatcher and a pub/sub system.
Watch the segment from scaling the comment service. The speaker clearly explains the problem of horizontally scaling the real-time servers and contrasts the "central dispatcher" (using a service like Zookeeper) with the "pub/sub" approach (using a message bus like Redis Pub/Sub or Kafka).
Let's outline the pub/sub architecture, which is generally simpler and more robust for this use case:
- Comment Management Service: Receives the
POSTrequest for a new comment. - Persistent Database (e.g., Cassandra): The service first writes the comment to a durable database. This ensures comment history is saved. Your experience with system design for high availability is relevant here; choosing a database like Cassandra, which favors availability, aligns with our non-functional requirements.
- Message Bus (e.g., Redis Pub/Sub): After a successful database write, the service publishes the new comment to a specific channel or topic on the message bus (e.g., a topic named
comments:video-123). - Real-Time Messaging Servers: A fleet of horizontally-scaled servers, each maintaining SSE connections for thousands of viewers. Each server subscribes to the topics for the videos its connected viewers are watching.
- Fan-out: When a Real-Time server receives a message from a topic it's subscribed to, it iterates through its in-memory map of connections for that video and pushes the comment down the appropriate SSE connections.
This architecture is highly scalable. We can scale the Comment Management Service, the database, the message bus, and the Real-Time Messaging Servers independently based on their respective loads.
4. Senior and Staff-Level Refinements
Describing the pub/sub architecture is a solid senior-level answer. To push into staff-level territory, you must discuss the second-order problems and trade-offs that arise from this design.
A. Pub/Sub and Co-location Efficiency
A naive implementation where every Real-Time server subscribes to every topic is wildly inefficient. This is the "drinking from the firehose" problem. We need two key optimizations:
- Topic Partitioning: Instead of a topic per video (which doesn't scale), we can hash the
video_idto a fixed number of topics (e.g.,hash(video_id) % 1024). Each Real-Time server only needs to subscribe to the topics relevant to the viewers it's currently serving. - Viewer Co-location: Ideally, all viewers of the same stream should be connected to the same Real-Time server. This minimizes the number of servers that need to subscribe to a given topic. We can achieve this using a Layer 7 load balancer with a consistent hashing strategy based on the
video_idfrom the initial connection request.
Design FB Live Comments: Hello Interview Mock
This mock interview clip demonstrates how an interviewer might push a candidate to refine their design. The feedback provided is invaluable for understanding how to move from a good design to a great one.
Watch the interviewer's feedback from the feedback section. The key points are using an in-memory map on each real-time server to manage subscriptions, and using a Layer 7 load balancer with consistent hashing for co-location. This simplifies the architecture by removing the need for a separate, distributed cache for connection info.
B. The "Mega-Stream" Problem
What happens when the World Cup final goes live, attracting 20 million viewers and generating 10,000 comments per second? At this point, the comment stream is unreadable. The user experience goal shifts from reading a conversation to feeling the energy of the crowd. This change in requirements allows for a radical architectural shift.
Design Facebook's Live Comments System | Hello Interview System Design in a Hurry
This part of the Hello Interview article contains the key insight for a staff-level answer.
In the section on scaling, find the subsection titled Part 2: Mega-Streams. The core idea is to switch from a real-time push model (SSE) to a near-real-time pull model using a CDN. This is a brilliant optimization that leverages existing infrastructure to handle extreme scale.
The mega-stream architecture works as follows:
- Snapshot Generation: A service takes snapshots of the most recent ~100 comments for the mega-stream every 1-2 seconds.
- CDN Delivery: This snapshot (a simple JSON file) is written to a CDN.
- Client Polling: Clients switch from maintaining an SSE connection to simply polling this JSON file from the CDN every 1-2 seconds.
- Simulated Stream: The client then animates the new comments from the snapshot onto the screen over the polling interval, creating the illusion of a continuous stream.
This approach is incredibly scalable because CDNs are built to serve static files to millions of users simultaneously. It also dramatically reduces infrastructure costs. Proposing this solution demonstrates that you can re-evaluate requirements at extreme scale and adapt your architecture accordingly.
Conclusion
In this lesson, we designed a scalable system for live comments, moving from basic requirements to advanced, staff-level optimizations. You now have a comprehensive framework for answering this common and challenging system design question.
Key Takeaways:
- Choose the Right Protocol: For real-time systems with a heavy read/write imbalance like live comments, Server-Sent Events (SSE) are often a more efficient and simpler choice than WebSockets.
- Scale with a Message Bus: Decouple comment ingestion from broadcasting using a pub/sub system (like Redis Pub/Sub). This allows the real-time connection layer to be scaled horizontally and independently.
- Optimize for "Mega-Streams": At extreme scale, the user experience requirements change. Acknowledging this and switching from a push model (SSE) to a CDN-based pull model is a key staff-level insight that demonstrates deep architectural thinking.
In our final lesson of this module, we will explore another facet of real-time communication: WebRTC. We'll examine the role of WebRTC and signaling servers in establishing peer-to-peer connections, the technology that powers applications like Google Meet and Discord video chat.