← Back to All Questions
Medium~45 minReal-Time Systems

Design Live Comments System

FacebookYouTubeTwitchRedditDiscord

📝 Problem Description

Design a live comments system for live streaming where comments appear in real-time. Handle millions of concurrent viewers, spam prevention, and low-latency message delivery.

👤 Use Cases

1.
Viewer wants to posts comment so that comment appears to all viewers
2.
Viewer wants to joins stream so that receives live comments
3.
Moderator wants to deletes comment so that removed from all viewers
4.
System wants to detects spam so that blocks message

✅ Functional Requirements

  • Post comments in real-time
  • Deliver to all viewers < 500ms
  • Moderation (delete, ban)
  • Rate limiting per user
  • Reply threading optional
  • Emoji reactions

⚡ Non-Functional Requirements

  • Support 1M concurrent viewers per stream
  • Latency < 500ms end-to-end
  • 99.9% message delivery
  • Handle viral streams (10M+ viewers)

⚠️ Constraints & Assumptions

  • Millions of concurrent WebSocket connections
  • Message volume can spike during events
  • Spam can overwhelm system

📊 Capacity Estimation

👥 Users
10M concurrent users, 100K active streams
💾 Storage
1TB (comments retention 30 days)
⚡ QPS
Writes: 100K/sec, Fan-out: 1B messages/sec peak
📐 Assumptions
  • 10M concurrent users
  • 100K active streams
  • Average 100 viewers per stream
  • 1 comment per viewer per minute

💡 Key Concepts

CRITICAL
WebSocket Fan-out
Pub/Sub to distribute comments to all viewers via WS servers.
HIGH
Connection Affinity
Route viewers to same WS server for efficiency.
HIGH
Rate Limiting
Limit comments per user to prevent spam.
MEDIUM
Slow Mode
Global rate limit when chat is too fast.

💡 Interview Tips

  • 💡Start with the WebSocket architecture
  • 💡Discuss the fan-out pattern for delivery
  • 💡Emphasize the moderation requirements
  • 💡Be prepared to discuss rate limiting
  • 💡Know the tradeoffs between push and pull
  • 💡Understand the persistence vs real-time balance