Design Reddit
Understanding the Problem
👽 What is Reddit? Reddit is a collection of communities called subreddits, each about one topic. Users submit posts (a link, text or an image) to a subreddit, vote them up or down, and discuss them in threaded comments where any comment can have replies of its own. Votes decide what rises: each subreddit has a "hot" page that mixes score and freshness, and each user gets a home feed built from the subreddits they've joined.
You may also be asked to design Quora or Stack Overflow. They are the same problem underneath. A subreddit becomes a topic or a tag, a post becomes a question, top-level comments become answers, and votes decide the order. Stack Overflow adds two things on top: the asker can mark one answer as accepted, and votes earn the author reputation, which unlocks privileges. We'll build Reddit and then cover what changes for the Q&A variants in a deep dive.
Functional Requirements
Reddit has a lot of surface area (chat, awards, moderation tools, ads), so agree early with your interviewer on the core loop: post, vote, read ranked lists, discuss.
Core Requirements
- Users should be able to create a post in a subreddit.
- Users should be able to upvote or downvote posts and comments, and change or remove their vote.
- Users should be able to view a subreddit's posts sorted by hot, new or top, and a home feed built from the subreddits they've joined.
- Users should be able to read and write nested comments on a post, sorted by best or new.
Below the line (out of scope)
- Creating and moderating subreddits (moderator queues, rules, bans).
- Search, chat, notifications and ads.
- Personalized recommendations beyond "posts from subreddits you joined".
Non-Functional Requirements
Ask your interviewer for scale. We'll assume 50M daily active users, each loading about 10 feed pages and 5 comment pages a day and casting about 10 votes. Users create 1M posts and 5M comments a day.
Core Requirements
- The system should serve feeds and comment pages fast: under 200ms at p99 for the API.
- The system should be highly available for reads. A vote count that is a few seconds stale is fine; a page that won't load is not.
- The system should count votes correctly in the end: one vote per user per item, no double counting on retries, and changes of mind applied as a delta.
- A user should see their own vote and their own new comment immediately (read-your-writes for the author).
- The system should cope with viral posts that take thousands of votes and comments per minute.
Below the line (out of scope)
- Multi-region active-active writes.
- Detecting vote manipulation in depth (we'll mention it, but it's its own problem).
Some arithmetic, because it tells us where the work is:
- Reads: 50M × 15 page loads = 750M a day, about 8.7k/s on average and maybe 25k/s at peak.
- Votes: 50M × 10 = 500M a day, about 5.8k/s on average and around 20k/s at peak.
- Content: 6M posts and comments a day is about 70 writes/s. Tiny.
- Vote storage: a vote row is roughly 40 bytes (user ID, target ID, value, timestamp, overhead), so 500M a day is about 20GB a day, or around 7TB a year.
Votes outnumber new content about 80 to 1. Posting and commenting are easy; the interesting parts are counting votes on hot items and keeping ranked lists fresh while scores change thousands of times a second.
Reddit's ranked lists are the same for every viewer of a subreddit. That's what makes them cheap: compute "hot" for r/aww once, then serve it to every reader from memory. Personalization only happens at the merge step of the home feed.