← Back to All Questions
Medium~45 minSocial Media

Design Reddit-like Threaded Comments

RedditHacker NewsDiscourseStack OverflowMeta

📝 Problem Description

Design a threaded comment system like Reddit. Support nested replies, voting, sorting (best/new/top), collapsing threads, and efficient retrieval of deeply nested conversations.

👤 Use Cases

1.
User wants to posts comment so that comment appears in thread
2.
User wants to replies to comment so that creates nested reply
3.
User wants to votes on comment so that score updated
4.
User wants to loads thread so that sees sorted, nested comments

✅ Functional Requirements

  • Create comments on posts
  • Reply to existing comments (nested)
  • Upvote/downvote comments
  • Sort by best/top/new/controversial
  • Collapse comment threads
  • Load more replies on demand
  • Edit and delete comments

⚡ Non-Functional Requirements

  • Handle 10M comments per day
  • Thread loading < 500ms
  • Support threads with 10K+ comments
  • Vote counting near-real-time

⚠️ Constraints & Assumptions

  • Deeply nested threads can be huge
  • Voting must handle hot threads
  • Sorting complex for nested structure

📊 Capacity Estimation

👥 Users
100M daily users
💾 Storage
10TB (comments)
⚡ QPS
Reads: 100K/sec, Writes: 10K/sec, Votes: 50K/sec
📐 Assumptions
  • 100M daily users
  • 10M new comments per day
  • 50M votes per day
  • Average thread depth: 5 levels

💡 Key Concepts

CRITICAL
Materialized Path
Store ancestry path for efficient tree queries.
HIGH
Wilson Score
Ranking algorithm balancing upvotes vs sample size.
HIGH
Depth-limited Loading
Load N levels, then "load more".
MEDIUM
Vote Aggregation
Redis for real-time, async persist to DB.

💡 Interview Tips

  • 💡Start with the tree data model
  • 💡Discuss the materialized path approach
  • 💡Emphasize the ranking algorithm
  • 💡Be prepared to discuss pagination
  • 💡Know the tradeoffs between tree representations
  • 💡Understand the caching strategy