Skip to content

Design Reddit

A system design interview walkthrough for a forum like Reddit: vote counting, ranked listings, comment trees and caching a read-heavy front page.

Intermediate22 minUpdated 2 December 2026

Before this: Caching, Data Partitioning (Sharding), Message Queues

"Design Reddit" is a good question because the product is so simple to describe and the interesting part hides in the details. People post links and text into communities, vote on what they see, and discuss in nested comments. A page of results is ordered not by time but by what the crowd likes.

The interviewer is checking whether you can separate a write-heavy signal (votes) from a read-heavy view (the ranked listing), and whether you know that these two should not be tied together by a database sort on every page load. They also want to see how you store a tree of comments, and how you keep a single viral post from taking everything down.

The shared building block is the cache, and you will lean on it throughout. A pure score ranking with no posts and no comments is a smaller cousin of this problem: see Design a Gaming Leaderboard. If your instinct is the follower feed of Design Twitter, notice what differs: here the audience is a community, and the order comes from votes, not from who you follow.

Clarify the requirements

Functional requirements:

  1. Users create communities (subreddits) and join them.
  2. Post a link or text to a community.
  3. Upvote or downvote a post or a comment, once per user per item.
  4. View a community's listing sorted by hot, new or top (for a time window), and a home page that merges the communities you joined.
  5. Comment on a post, with replies nested to any depth, sorted by best.
  6. See the score and comment count.

Out of scope, said aloud: moderation tooling, awards, chat, search, ads, recommendations for communities.

Non-functional requirements: these decide the architecture.

  • Reads dominate. For every vote or post, many people only look.
  • Listings must be fast and mostly fresh. A score that is a few seconds old is fine. An empty or broken front page is not.
  • Votes must not be double-counted. One vote per user per item, and changing a vote moves the score by the right amount.
  • Traffic is extremely uneven. A few posts and communities receive most of it, and a post can go viral in minutes.
  • Comment threads can be very deep and very wide, with tens of thousands of comments on one post.

Estimate the scale

Assume 50 million daily active users. Each casts about 8 votes a day, writes about half a comment or post, and views about 150 posts (listing items and threads).

Writes: 8 votes plus 0.5 content items is 8.5 write operations per user. 50M × 8.5 = 425 million a day, or 425M ÷ 86,400 ≈ 4,900 per second, and about 15,000 per second at peak (3x). Of those, votes are about 400M a day, or 4,600 per second.

Reads: 50M × 150 = 7.5 billion a day, about 87,000 per second. The read-to-write ratio is roughly 18:1.

Storage: a vote is small (user, item, direction, time), about 40 bytes. A post or comment is about 1 KB. So 400M × 40 B + 25M × 1 KB is about 41 GB a day. Averaged over 425M writes that is about 100 bytes per write. Over five years: about 15 TB a year, roughly 78 TB.

Hot listing: a subreddit page is requested far more often than anything else. If the 10,000 busiest communities each hold their top 1,000 posts as IDs plus scores, that is 10,000 × 1,000 × 16 B ≈ 160 MB. Trivial to keep in memory.

"4,900 writes a second is nothing, and the whole listing index for the busiest communities fits in one cache node. This is not a storage problem. It is a problem of when the ranking is computed: on every read it would be a sort over millions of rows 87,000 times a second, so it must be computed once on the write side and served from memory."

The capacity estimator reproduces the rates and the five-year total.

API and data model

GET  /v1/r/{community}/posts?sort=hot|new|top&t=day&after=<cursor>
GET  /v1/posts/{id}                                  -> post + top comments
GET  /v1/posts/{id}/comments?parent=<id>&sort=best&limit=50
POST /v1/posts           { community, title, body|url }
POST /v1/{kind}/{id}/vote   { dir: 1 | 0 | -1 }
POST /v1/posts/{id}/comments { parentId?, text }
posts      (post_id PK, community_id, author_id, title, body, created_at, up, down, score)
comments   (post_id PK, comment_id CK, parent_id, path, author_id, text, up, down)
votes      (user_id PK, item_id CK, dir)              -- one row per user per item
listing    Redis sorted set per (community, sort): member = post_id, score = rank key

The non-obvious choice: the votes table is the source of truth for who voted, and up, down and score on a post are derived, eventually consistent counters. That split lets the vote write stay cheap and idempotent while the displayed score catches up.

High-level design

We simulate the vote and listing path: an API in front of a listing cache and the post store, with votes published to a stream and a ranking worker that updates the listing.

The community API serves listings from a Redis cache, stores posts in Postgres and publishes votes to Kafka, where ranking workers refresh the cached listings.clientscommunity apilisting cacheposts and votesvote streamranking workers
The community API serves listings from a Redis cache, stores posts in Postgres and publishes votes to Kafka, where ranking workers refresh the cached listings.
  • The API serves a community's listing from the cache and loads post details from Postgres.
  • Votes go to a Kafka stream, and ranking workers write updated scores into the listing cache.
Describe this diagram

Components

  • clients (Client)
  • community api (Service)
  • listing cache (Redis)
  • posts and votes (PostgreSQL)
  • vote stream (Kafka)
  • ranking workers (Service)

Connections

  • clients sends to community api
  • community api sends to listing cache
  • community api sends to posts and votes
  • community api sends to vote stream
  • vote stream sends to ranking workers
  • ranking workers sends to listing cache

Run it, then try adding more vote traffic or turning the listing cache off. Postgres is the first thing to feel it.

The write path for a vote: the API records (user, item, dir) in the vote store, which is an idempotent upsert, and publishes a small event with the change in direction. It returns at once.

The read path for a listing: the API reads the page of post IDs from the cached sorted set, fetches the post bodies from a second cache (or Postgres on a miss) and returns. A listing request never sorts anything.

The ranking path: workers consume vote events, update each post's counters and recompute its rank key, then write the new score into the sorted sets it belongs to.

The interesting problem: ranked listings under constant votes

Ordering a community by "hot" while thousands of votes arrive each second is the heart of the question.

Approach A: sort in the database on every request

SELECT ... WHERE community_id = ? ORDER BY score DESC LIMIT 25.

Good: trivially correct and always fresh.

Bad: an index on (community_id, score) has to be updated on every vote, which makes the hottest posts the hottest rows. At 87,000 reads a second, even an indexed top-25 query puts constant load on one database, and a time-decayed score cannot be indexed directly if it depends on "now".

Approach B: recompute rankings on a timer

A batch job recomputes each community's top list every minute and stores it.

Good: simple, and read load is just cache hits.

Bad: votes appear on the page with up to a minute of delay, and a post that is exploding is invisible until the next run. The work is also done for communities that nobody is viewing.

Approach C: incremental updates into per-community sorted sets

Compute a rank key for each post that only changes when its votes change, and keep the top N per community in a sorted set such as a Redis ZSET.

The key insight is in the formula. A "hot" score in the common family takes the form log(net votes) + created_at / constant. The first term only changes on a vote. The second is fixed at creation, because the post's age is built into its timestamp rather than recomputed from "now". So a post's rank key changes only when somebody votes on it, and old posts sink as new ones, with larger timestamp terms, arrive. Nothing needs to be recomputed as time passes.

The recommended design is C with coalescing. A worker batches votes per post for a few seconds, so a post receiving 100 votes a second causes one sorted-set update, not 100. Cap each sorted set at the top 1,000 posts, since no one pages past that. Rebuild a set from the database if it is lost.

Comment trees and sorting

Comments form a tree under each post, and a thread can hold tens of thousands of nodes.

Storage. Keep all of a post's comments in one partition (post_id as the partition key), each with its parent_id and a materialized path such as 0004.0012.0003. A path sorts a depth-first reading order and lets you fetch a subtree with a prefix range. Plain adjacency (parent_id only) needs one query per level.

Loading. Never return the whole tree. Return the top 200 comments by best score, to a limited depth, with "load more replies" stubs that carry the parent ID. The client expands one branch at a time.

Sorting by best. Sorting by net votes favors early comments. A better method ranks by the lower bound of a confidence interval on the fraction of positive votes (the Wilson score interval), so a comment with 8 of 10 positive votes beats one with 1 of 1. Compute it when a comment's votes change and store it as the sort key.

Bottlenecks and failures

A viral post. Millions open the same thread. The listing and the post body come from cache, and the comment page is the real load. Cache the first page of comments for a few seconds, per sort, and let all requests share it. Without that you get a cache stampede on one key, which coalescing concurrent misses fixes.

Vote manipulation. Brigading and bot rings distort the ranking. Rate-limit votes per user and per IP, ignore or down-weight votes from new or suspicious accounts, and delay the display of some vote counts. Rank on a score that you can adjust, not on the raw tally.

The vote stream falls behind. Scores lag but reads and writes work. Alert on consumer lag, and replay from the vote store to recompute counters if needed.

What if the listing cache is down? Serve the community's new listing straight from an indexed database query (cheap, since it is ordered by time) and degrade hot to a stale snapshot. The page loads, and its order is slightly worse.

Trade-offs to name aloud

  • Derived counters over exact ones: a score may lag the votes by seconds, in exchange for cheap, idempotent vote writes.
  • Incremental sorted sets over on-demand sorting: more machinery on the write side, in exchange for constant-time page loads.
  • Top 1,000 per listing: pages beyond that are not served from the fast path, and nobody notices.

What interviewers listen for

  • A working answer: posts and comments tables, a votes table, a cache for the front page and a score field updated on vote.
  • A strong answer: separates vote truth from derived counters, explains why listings are precomputed in sorted sets, states a hot-ranking formula and the property that the key changes only on votes, and coalesces vote updates.
  • A standout answer: also models the comment tree with paths and "load more" stubs, ranks comments with a confidence bound rather than raw net votes, protects the ranking against manipulation, and degrades hot to a stale snapshot when the cache fails.

Check your understanding

Common mistakes

Sorting in the database on every request. It looks right for an interview whiteboard and collapses at 87,000 reads a second. Precompute the order.

Counting votes without a one-per-user guarantee. Without a unique (user, item) row, retries and double clicks inflate scores. The vote write must be idempotent.

Loading a whole comment tree. A thread with 40,000 comments cannot be sent in one response. Cap depth and count, and use "load more" stubs.

Ignoring manipulation. Any ranking that is easy to pump will be pumped. Mention rate limits, account age weighting and score fuzzing.

Practice

A community with 20 million members posts a thread that gets 300,000 comments in two hours. Which parts of the design get hot, and what do you change?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Think about the single partition that holds all the comments, and about what the page asks for first.

Show a strong answer

One partition holds the whole thread. With post_id as the partition key, all 300,000 comments sit in one place, and every write and read for that thread goes there. At the peak, 300,000 comments in two hours is about 42 writes a second, which a partition handles. Reads are the larger concern.

Reads for the first page hit the same rows. Everyone asks for the top 200 comments by best. Cache that page per sort for a few seconds and share it. Serve "load more" requests from the partition, since they are far fewer.

If the partition itself becomes the limit, split a very large thread by hashing comment_id into a few sub-partitions (post_id#k) and merge on read. Do this only for threads that cross a size threshold.

The pattern worth keeping: a hot object needs a short shared cache for reads and coalesced counters for writes, and only then a partition split.

You want a home page that merges the top posts from the 40 communities a user has joined. How do you build it without a heavy query on every visit?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

You already have a sorted set per community. Decide whether to merge on read or to store a result per user.

Show a strong answer

Merge on read from the per-community sets. Take the top 50 from each of the 40 sets, then merge them by rank key in memory. That is 2,000 candidates, which costs microseconds of CPU and 40 cache reads that you can pipeline into one round trip. It needs no per-user storage.

Cache the merged page briefly. Store the user's merged result for 30 to 60 seconds, so refreshes and pagination are consistent, and the second page continues from a cursor into the same candidate list.

The pattern worth keeping: when inputs are already sorted and small, merge them at read time rather than materializing a result for every user.

Key takeaways

  • Votes are the truth, and scores are derived. Keep a unique vote per user per item.
  • Precompute listings in per-community sorted sets rather than sorting on read.
  • Choose a ranking whose key changes only on votes, so you can update it incrementally.
  • Coalesce updates for hot posts to turn a thousand writes into a handful.
  • Store comment trees with paths, return a bounded slice and load the rest on demand.
  • Plan for manipulation and for the viral post before they happen.

Further reading

  • Evan Miller, "How Not To Sort By Average Rating" (2009): the Wilson score interval for ranking items with few votes.
  • Redis documentation, "Sorted sets": the data structure behind incremental ranked listings.

Check yourself

3 questions in this lesson. Answer each once to complete it.

Practice this

Lessons in this track