Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

System Design (High-Level Design)  Module 23 – Case studies: social, feeds and search

Design a Q&A forum like Quora or Reddit

Design a Q&A forum like Quora or Reddit: threaded answers and comments, one vote per person, fair ranking of answers and posts, and moderation at scale.

  • Intermediate
  • 25 minutes
  • Examples run with Python 3.14.8, Pyodide 314.0.7, Node.js 24.21.0, quickjs 0.32.0 and sql.js 1.14.2
  • By MySmartCoPilot
Free intro, Pro: 5 of 25 minutes free
Free: Thread pages outnumber new comments sixty to one. With a pass: the other 11 sections and 3 interview answers, about 20 minutes.

What you will learn

  • Estimate the reads, writes, votes and storage of a Q&A forum
  • Model posts, threaded comments and votes so that a subtree loads in one query
  • Rank answers and posts fairly as votes accumulate
  • Design moderation whose removals reach caches, search and apps

Before you start

What you’ll learn · Before you start

What you will learn

  • Estimate the reads, writes, votes and storage of a Q&A forum
  • Model posts, threaded comments and votes so that a subtree loads in one query
  • Rank answers and posts fairly as votes accumulate
  • Design moderation whose removals reach caches, search and apps

Before you start

On this page

A popular Q&A forum serves about 7,000 thread pages a second, 21,000 at the evening peak, while people add only 116 answers and comments and cast 2,315 votes a second. To design a Q&A forum like Quora or Reddit, get three things right: threads, votes and moderation. Every thread is a tree of answers and replies that should load in one read; each person casts at most one vote per item, and the counts must stay cheap to show; and a removal must reach every copy of a page within a minute.

The design caches pages hard for readers who are not signed in, keeps each thread on one shard, stores every vote as a row keyed by voter and item, ranks answers with a confidence bound and posts with a score that favours new ones, and sends every change through one change log. This case study sizes the forum, then follows its threads, votes, ranking and moderation.

Not affiliated

Based on public information about Quora and Reddit. MySmartCoPilot is not affiliated with Quora and Reddit, and Quora and Reddit’s real architecture may differ from what this lesson describes.

Thread pages outnumber new comments sixty to one

Ask before designing: questions that gather many answers, or links and posts with comment threads? Whether you are asked to design a Q&A forum like Quora or a discussion site like Reddit, the data model is the same, a post with a tree of comments, so plan for both. Are there communities with their own moderators? How deep may replies nest? May people change their votes? What must disappear quickly when removed?

Functionally, people post questions or links, answer and reply at any depth, vote up or down once per item and change their vote, read threads sorted by best, top or new and community pages sorted by hot, search, and report content. Moderators remove, lock and ban. The non-functional requirements: a thread page within 300 ms at the p99 (99th percentile): The latency within which 99 % of requests finish, so the slowest 1 % take longer. Tail latency is read from such high percentiles, because an average hides the slowest requests. More in “Latency, throughput and percentiles”, vote counts that may trail by a few seconds but never count one person twice, a removal that is gone everywhere within a minute, and a site that stays readable when writes fail.

Quantity Assumption Result
Thread pages 40 million people a day × 15 pages 600 million a day: 6,944 a second, about 21,000 at peak
Answers and comments 10 million a day 116 a second
Votes 200 million a day 2,315 a second; one viral post can draw thousands a second alone
Text 10 million × 1 KB with metadata 10 GB a day, about 3.65 TB a year
Votes kept 200 million × 24 bytes 4.8 GB a day, about 1.75 TB a year

Reads dominate: 6,944 thread pages a second against 116 new comments, so most pages should come from a CDN or a cache, and the store should serve only misses and signed-in readers. Votes are the busiest writes, and they never touch a thread’s text, so they get their own service and counters. In the first design, reads flow down through the CDN and the thread cache to the store, and every change, whether a comment, a vote or a removal, goes to a change log that feeds the ranking jobs, the search index and cache invalidation.

Q&A forum: CDN, API, thread, vote and moderation services, thread cache and store, counters, a change log, ranking jobs and search.Web and appsCDNpages for readerswho are not signed inAPI gatewayThread serviceposts, answers, commentsVote serviceone vote per personModerationreports, filters, queuesThread cacheThread storesharded by postVote store andcountersChange logRanking jobsbest, hot, topSearch indexmisses andsigned-in readersread and writevotereportevery changescore changesremovalsinvalidate

The first high-level design of a Q&A forum

Text description of the diagram

The diagram shows the parts of the design from top to bottom.

  1. Web and app clients go through a CDN, which serves cached pages to readers who are not signed in. Misses and signed-in readers reach the API gateway.
  2. The gateway sends reads and writes of posts, answers and comments to the thread service, votes to the vote service and reports to moderation.
  3. The thread service reads through a thread cache and stores threads in a thread store sharded by post. The vote service records one vote per person and keeps the counters.
  4. Every change in the thread store, every score change and every removal by moderation goes to a change log.
  5. The change log feeds the ranking jobs, which keep the best, hot and top lists, the search index, and the invalidation of the thread cache.

Follow one read by someone who is not signed in, then one vote by someone who is, through that design:

Interactive · step by step One read and one vote through the forum Step through a thread page read by someone who is not signed in, then a vote by someone who is, and see where each change goes.
One read and one vote through the forum, step 9 of 9. Showing Reader's app, CDN edge (miss: copy expired), API gateway, Thread service, Vote service, Thread cache, Vote counters (split for busy items), Thread store, Change log, Search index, Ranking jobs.missesevery changeinvalidateReader's appCDN edgemiss: copy expiredAPI gatewayThread serviceVote serviceone vote per personThread cacheVote counterssplit for busy itemsThread storesharded by postChange logSearch indexRanking jobsbest, hot, topone ordered record of every change

The drawing shows the whole scene; its 9 steps are listed below.

Every step as text
  1. A reader opens a thread. Someone who is not signed in opens a popular thread. Every such reader sees the same page, so the request goes first to the CDN edge nearest to them.
  2. Answered at the edge. The edge holds a recent copy of the page and answers at once. Thread pages outnumber new comments about sixty to one, so most reads end here.
  3. A miss goes on. When the edge's copy has expired, the request passes the API gateway to the thread service, which looks in the thread cache first.
  4. One shard, one read. On a cache miss the thread service reads the store. A thread's comments all sit on the shard of its post, so the page is one read, not one per comment.
  5. A signed-in reader votes. A reader who is signed in sends an upvote. Votes never touch a thread's text, so the gateway sends them to their own service.
  6. One vote per person. The vote is stored as a row keyed by the voter and the item, so a second vote by the same person replaces the first instead of counting twice. The counters take the change.
  7. Every change goes to the log. New comments, vote changes and removals all go to one change log, in order for each item. Nothing downstream is written by the services directly.
  8. The log feeds everything else. Ranking jobs re-sort the community's lists, the search index takes new and removed comments, and the thread cache drops pages that changed.
  9. Reads and writes apart. Reads end at the edge, the cache or one shard; writes end in the log. A burst of votes on a viral post never slows the thread page down.

Checkpoint

Check the estimate and the read path

  1. Question 1 of 3 40 million people a day each open 15 thread pages. How many thread pages a second is that on average?

    Type a number.

    A hint

    A day has 86,400 seconds.

    Show the answer: Question 1 of 3

    Answer: 6944 pages a second (anything from 6250 to 7638 counts)

    40,000,000 × 15 = 600 million pages a day, and 600,000,000 ÷ 86,400 ≈ 6,944 a second; at an evening peak of three times the average, about 21,000. Most of them can come from a CDN, because readers who are not signed in all see the same page.

  2. Question 2 of 3 The forum receives 200 million votes a day. How many votes a second is that on average?

    Type a number.

    Show the answer: Question 2 of 3

    Answer: 2315 votes a second (anything from 2083 to 2547 counts)

    200,000,000 ÷ 86,400 ≈ 2,315 votes a second. The average is easy; the hard case is one viral post that draws thousands of votes a second on its own.

  3. Question 3 of 3 A reader who is not signed in opens a popular thread. Which parts can be on the path of that request?

    Choose every answer that is right.

    Show the answer: Question 3 of 3

    Answer:

    • The thread store, when the thread cache misses
    • The thread cache, when the CDN misses
    • The CDN, which may answer with a cached copy of the page

    A reader without an account sees the same page as every other such reader, so the CDN can answer, then the thread cache, then the store. Moderation and the ranking jobs work beside the read path: they change the data, and the change reaches the caches through events.

A round then goes deeper. These are the questions it usually opens, each with the idea behind its answer:

  • Threads as trees: each comment stores the path of its ancestors, so a whole subtree is one range of an index.
  • One vote per person: a vote is a row keyed by voter and item, and counts live in sharded counters.
  • Ranking answers: “best” sorts by the lower bound of a confidence interval for the share of upvotes.
  • Ranking posts: “hot” adds the time a post was made to the logarithm of its votes.
  • Moderation: a removal travels as an event to the cache, the CDN, the search index and the ranked lists.
  • Hot threads: a viral thread is cached briefly at the CDN, and its counters are split.

An answer is judged on its requirements and estimates, the data model for threads and votes, ranking, moderation, caching and failure handling.

Every record is keyed for the read it serves Pro: opens with a Pro, Premium or Ultimate pass

In this part:

  • A materialised path reads a subtree as one range
  • One row per voter and item counts every vote once
  • A confidence bound ranks answers; posting time ranks posts
  • A removal is a state change that reaches every copy
  • A 30-second edge lifetime absorbs a viral thread
  • At ten times the load, vote rows and counters give out first
    • Bottlenecks at 10× and 100×
    • Failure drills
    • Designs this one rejects
  • What each level covers, and a 45-minute self-mock
  • Practise: order a thread best first
    • Order a thread best first, to a fixed depth
  • Interview questions
    • A post goes viral: 8,000 votes a second land on it and 60,000 people a second open its thread. Votes time out and the page is slow. How do you record the votes, show the counts and serve the thread without overloading one row?
    • Answers are sorted by upvotes minus downvotes, and people who write new answers say nobody ever sees them. Propose a ranking for the best answers and one for a community's front page, and show with numbers why each is fairer.
    • A moderator removes a harmful answer, but it stays visible for an hour: in the cached thread page, in search results and in the apps of people who loaded it earlier. Design removal so that it takes effect everywhere within a minute.
  • Key takeaways

2 diagrams · 3 runnable examples (SQL) · 1 exercise with sample tests · 3 interview answers · about 57 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Read a complete sample first: Design a news feed

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.