System Design LabSystem Design QuestionsDesign Reddit

Design Reddit

MediumSocial Mediasocialrankingfeedcaching

Question Overview

Design a Reddit-style discussion platform built around communities, posts, nested comments, and voting. The core challenges are counting hundreds of millions of votes a day without hot rows, ranking posts by hot and top, and loading deep comment trees quickly.…

Sign up to see the full question and AI interviewer

Requirements

  • Create and subscribe to subreddits, and submit link, text, or image posts to a subreddit
  • Comment on posts and reply to any comment, forming arbitrarily deep, collapsible comment trees
  • Upvote or downvote posts and comments with one changeable vote per user per item, never double counted
  • Subreddit and home feeds sorted by hot, new, or top over a day, week, or all time
  • Feed and post pages under 200 ms p99; reads stay available even if vote processing is degraded
  • Scores may lag by seconds, but users always see their own votes immediately (read-your-writes)

Back-of-the-envelope numbers

  • Page views: 100M DAU × 30 pages/day = 3B/day ÷ 86,400 s ≈ 35K QPS average, ~105K QPS at 3× peak
  • Votes: 200M/day ÷ 86,400 s ≈ 2.3K votes/s average, ~7K/s at 3× peak; a viral post at 6K votes/min is 100 increments/s on one counter
  • Content writes: 5M posts + 50M comments = 55M/day ÷ 86,400 s ≈ 640 writes/s average, ~1.9K/s at 3× peak
  • Content storage: 5M × 2 KB + 50M × 500 B = 10 GB + 25 GB = 35 GB/day ≈ 12.8 TB/year, excluding media in object storage
  • Vote records: 200M/day × ~30 B (user, item, direction, time) ≈ 6 GB/day ≈ 2.2 TB/year, kept to dedupe and allow vote changes
  • Listing cache: 100K subreddits × 4 sort orders × top 1,000 post IDs × 8 B ≈ 3.2 GB of IDs, a few times that with Redis overhead

Key components

  • Post and comment stores: sharded SQL keyed by post_id, each comment holding parent_id so a post's whole tree loads in one query
  • Vote service: upserts (user_id, item_id, direction) keyed by user and item and emits only the score delta, making repeat votes idempotent
  • Vote aggregator: consumes deltas from Kafka and applies batched increments per item every few seconds, avoiding hot-row contention on viral posts
  • Hot ranking: Reddit's open-sourced hot formula adds log10 of net score to creation time ÷ 45,000 s, so 10× the votes equals 12.5 hours of recency
  • Listing service: per-subreddit Redis sorted sets for hot, new, and top, updated only when an item's score changes
  • Home feed: fan-in on read by merging the cached hot lists of a user's subscriptions, since fan-out to 30M subscribers is impractical
  • Comment ranking: best sort by the Wilson score lower bound, with deep or low-scored branches truncated behind load-more links

Common mistakes

  • Running UPDATE posts SET score = score + 1 per vote, serializing thousands of writers on one hot row during a viral spike
  • Storing only a counter with no per-user vote records, so double votes and up-to-down switches (a −2 delta) cannot be handled
  • Fanning each new post out to every subscriber's feed, which means 30M writes for a single post in the largest subreddit
  • Fetching comment trees level by level with one query per parent, turning a 5,000-comment thread into thousands of round trips
  • Recomputing every post's hot score on a timer; with a creation-time term, a post's score changes only when votes arrive
  • Promising exact, strongly consistent vote counts, which forces synchronous coordination the product does not actually need

Likely follow-ups

  • How would you detect and discount coordinated vote manipulation by bot accounts?
  • How would you render a post with 100K comments without loading the entire tree?
  • How would you serve top of all time for a subreddit with ten years of posts?
  • How would you handle deleting a comment that still has replies beneath it?
  • How would you shard data when one subreddit is orders of magnitude larger than the rest?
  • How would you personalize the home feed beyond the user's subscribed subreddits?

No community solutions yet

Be the first to publish your solution

Practice ‘Design Reddit’ with an AI Interviewer

Get scored feedback on your diagram, scalability approach, and trade-offs. Free while we grow — up to 3 full interviews a day.