AlgoMaster Logo

Design Live Comments

Ashish

Ashish Pratap Singh

medium

In this chapter, we will aim to design a low-latency, scalable live comment system that allows thousands or even millions of users to exchange messages in real time during a live event.

Key challenges include:

  • Latency: Messages must be delivered in near real-time.
  • Fanout: A single message needs to be broadcast to millions of subscribers simultaneously.
  • Ordering: Comments should appear in a logical, roughly chronological order.

Let’s begin by clarifying the requirements.

1. Clarifying Requirements

Before diving into the design, let's narrow down the scope of the problem. Here’s an example of how a discussion between candidate and interviewer might flow:

After clarifying the requirements, we can summarize the functional and non-functional requirements.

1.1 Functional Requirements

  • Post Comments: Users can post short, text-based comments during a live event.
  • Real-Time Viewing: Users can view new comments posted by others in real-time.
  • Playback: Users can replay the stream with synchronized comments (time-aligned with the video) after the event ends.

1.2 Non-Functional Requirements

  • High Scalability: Support millions of concurrent viewers and thousands of new comments per second.
  • Low Latency: Deliver comments to clients within sub-second latency (< 500 ms ideally).
  • Reliability & Durability: Once accepted, a comment should never be lost even during failures.
  • Ordering: Comments should appear in approximately the order they were sent. Strict ordering is difficult in a distributed system, but we should aim for a consistent experience.
  • Eventual Consistency: Small ordering differences or delays are acceptable as long as the user experience remains smooth.

2. Scale Estimation

Before designing the system, let’s estimate the scale we need to support.

Throughput Estimation

  • Incoming comments per second = 50,000 users × (1/10) = 5,000 comments/sec
  • Outgoing fanout = 5,000 comments/sec × 5,000,000 recipients = 25 billion message deliveries/sec. This massive number is the core challenge and will be handled via a distributed fanout architecture, not a single process.

Storage Estimation

  • Storage rate: 5,000 comments/sec × 150 bytes/comment = 0.75 MB/sec.
  • Storage per day: 0.75 MB/sec × 86,400 seconds/day ≈ 65 GB/day.
  • Storage per month (for playback): 65 GB/day × 30 days ≈ ~2 TB/month.

3. API Design

Premium Content

This content is for premium members only.