Design Reddit
medium 50 minA service like Reddit: communities, posts, nested comments and votes.
Video lesson · Chapter 1 of 5
A community page and one person's vote
Theory
Read or listen first. About 2 min.
What it is
A community discussion site lets people create topic communities, post in them, reply in nested threads and vote things up or down. Votes and time decide what others see first.
This is an exercise inspired by Reddit. It does not describe how that company runs its site today. Where we use a published Reddit formula or API rule, we link to it.
Why it exists
No editor can read a million posts a day. Voting lets a crowd sort them, and time decay gives new posts a chance.
The same three problems appear in many products: one vote for each person, counters that many people change at once, and lists ordered by a score that should favour the new.
A short history
1927
Edwin B. Wilson publishes the score interval later used to rank items with few votes.
October 1997
Slashdot launches, an early social news site.
2004 to 2005
Digg is founded in November 2004. Steve Huffman and Alexis Ohanian launch Reddit in June 2005.
15 October 2009
Reddit announces a new comment sorting system in a guest post by Randall Munroe. It uses a confidence interval, the Wilson score.
9 November 2017
The public reddit code repository is archived. Its sorting formulas can still be read there.
Words to know
- Community
- A topic group. Reddit calls it a subreddit.
- Vote state
- What one person chose on one item: up, down or nothing.
- Delta
- The change a new choice makes to a score, such as minus two from up to down.
- Hot score
- A number from votes and creation time that orders a feed.
- Wilson score
- A careful estimate of the share of up votes that is low when there are few votes.
- Materialised path
- A stored list of ancestors, such as 1/5/23, that finds a whole branch.
- Fullname
- An ID with a type prefix. In Reddit's API, t1 is a comment, t3 a link and t5 a subreddit.
- Karma
- A person's reputation from votes received.
Solve it like an interview
New to it? Start with Approach. Revising? Go straight to the mock.
- 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
- 2ScopeAsk what changes the design, then commit to a short list.
- 3NumbersWork out a number when the answer changes what you build.
- 4API and dataThe contract first, then the data that serves it.
- 5DesignStart with the smallest system that works. Change it only when something breaks.
- 6Deep divesCompare the options before you open them, then say which you would pick.
- 7Explain your choicesAnswer first. Then compare your reasoning.
- 8By levelThe same question is judged differently for mid, senior and staff.
- 9MockAnswer against the clock, then score yourself.
Understand it
Story
Beans at the school fair
Scope
What are we building?
People browse, join communities, post text, links, images or video, reply at any depth and vote. Feeds can be Hot, New, Top, Rising or Controversial.
Browse
One community, everything, or your own mix.
Vote
Up, down or nothing on posts and comments.
Discuss
Nested replies with a useful order.
Moderate
Rules, removal, reasons and appeals.
Similar applications
| Name | Known for |
|---|---|
| Hacker News | Technology links |
| Stack Overflow | Questions and answers with votes |
| Quora | Questions |
| Digg | Social news |
| Product Hunt | Voting on products |
| Lemmy | Federated communities |
| Discord forums | Threads inside chat |
| Discourse | Forum software |
The hard part
One row is easy, one count is hot
Ten thousand people voting on one post write ten thousand different rows. Only the total is shared. Seeing that difference removes most of the problem.
The finished system
Where the design ends up
The whole system
Read on
| Tab or page | For |
|---|---|
| Interviews: Scope, Numbers, API and data | Targets, sums, endpoints and tables |
| Interviews: Design, Deep dives | Six versions, votes, ranking, threads, home feed, karma |
| Visualize | Six flows, a viral post and failures |
| Sharded counters, change data capture | Hot counts and streams of row changes |
| Idempotency, API pagination | Safe repeats and cursors |
| Data partitioning, distributed caching | Where rows and copies live |
| Rate limiting, pub/sub, stream processing | Abuse limits, events and windows |
| Circuit breaker, retries | Slow parts |
Summary
The whole topic in one minute.
Separate the vote from the count. The vote is one row for each person and item, stored before we answer and never hot. The count is built from a stream of changes, batched, and may be a second old.
Rank with a score that uses creation time, so it changes only when votes change. Keep ready lists of IDs for communities and merge them for a home page. For a thread, load a light skeleton, sort it, and fetch text for the part people see.
- Store each person's choice as one keyed row. It makes repeats safe.
- Build counts from changes, in windows. They may lag by about a second.
- Hot scores use creation time, so nothing needs to be rescored as it ages.
- Lists hold IDs. Text, counts and your own votes are added in batches.
- Load a thread as a skeleton first, then only the visible text.
- Shown numbers may be approximate. Vote state may not.