Design a Real-Time Commenting System

System Design
Medium
Meta
131.1K views

Design the backend for a high-volume, low-latency commenting service for articles/videos. Focus on read/write separation and real-time updates.

Why Interviewers Ask This

Meta interviewers ask this to evaluate your ability to balance high read-throughput with low-latency writes in a globally distributed environment. They specifically test if you can design for real-time consistency using caching layers and pub/sub mechanisms while handling write amplification common in social feeds.

How to Answer This Question

1. Clarify requirements: Define scale (e.g., millions of daily active users), latency targets (sub-200ms reads), and consistency models (eventual vs. strong). 2. Outline the high-level architecture: Propose a read-heavy model where comments are cached aggressively, separating write paths from read paths. 3. Detail the write flow: Explain how to ingest comments via an API gateway, validate them, and push them to a message queue like Kafka or Pulsar for async processing. 4. Design the read path: Describe using Redis or Memcached as a hot cache layer, fetching data from a primary database only on misses, and utilizing fan-out-on-read or fan-out-on-write strategies depending on author popularity. 5. Address real-time updates: Integrate WebSocket connections or Server-Sent Events to push new comments instantly to subscribers without polling. 6. Discuss scalability: Mention sharding strategies for the database and partitioning topics by article ID to handle uneven traffic distribution.

Key Points to Cover

  • Explicitly defining the read/write ratio to justify the chosen architecture
  • Demonstrating knowledge of asynchronous processing via message queues like Kafka
  • Proposing a specific caching strategy (Redis) with clear invalidation logic
  • Explaining the mechanism for real-time delivery using WebSockets or similar protocols
  • Addressing data partitioning strategies to handle hot partitions for popular articles

Sample Answer

To design a real-time commenting system for Meta-scale traffic, I would prioritize read performance since users consume far more content than they create. First, I'd define the API contract to support pagination and sorting by recency. For the write path, incoming requests hit an API Gateway that validates input and pushes the comment payload into a Kafka topic partitioned by Article_ID. This decouples ingestion from storage, allowing us to absorb traffic spikes. A consumer group processes these messages, enriches them with user metadata, and persists them to a NoSQL database like Cassandra or DynamoDB, which offers horizontal scalability. For reads, we implement a strict separation. When a user loads an article, the system checks a Redis cache first. If the comments are present, we return them immediately; otherwise, we fetch from the database and populate the cache. To achieve real-time updates, we utilize a Pub/Sub pattern where the Kafka consumer broadcasts a notification to a WebSocket service whenever a new comment arrives. Connected clients subscribe to specific Article_ID channels and receive instant push notifications. We must also handle edge cases like spam filtering, which runs asynchronously before persistence. Finally, we ensure global availability by deploying this across multiple regions with active-active replication for the cache layer, ensuring sub-second latency for users worldwide regardless of their physical location.

Common Mistakes to Avoid

  • Focusing solely on database schema without addressing the high-volume read bottleneck
  • Ignoring the need for a message queue and attempting synchronous database writes for every request
  • Overlooking how to handle 'hot' articles that generate massive write contention
  • Forgetting to explain how real-time updates reach the client without constant polling

Practice This Question with AI

Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.

Start Practicing

Related Interview Questions

Browse all 150 System Design questionsBrowse all 71 Meta questions