🎓 A1Learner
🔍
0 of 64 lessons completed

Design Reddit

Reddit is a forum service organised into communities that their members run. Members post, comment and vote, and the votes order what a community shows first.

The ask

Each community has a topic, its own rules and its own moderators. Moderators are members who volunteer to keep order.

A member posts text, a link or an image to one community. Other members comment, and comments reply to comments.

Votes push posts up or down. A community page shows the strongest posts first.

One account reads many communities. A home page mixes the communities a member joined.

Estimate the scale

Communities number 100,000.

Posts and comments together reach 100,000,000 a day.

100,000,000 posts and comments / 86,400 seconds = about 1,157 per second.

Votes reach 1,000,000,000 a day.

1,000,000,000 votes / 86,400 seconds = about 11,574 votes per second.

Votes outnumber posts by far. The vote path is the hot path.

API and data

A post record holds the community ID, the author and the content. It also holds the time and the vote score.

A comment record holds its post ID and its parent comment ID. The parent link is what makes the tree of replies.

A vote record holds the voter, the target and the direction. One voter holds at most one vote on one target.

The community operation returns one page of posts in display order. The comments operation returns one branch of the tree at a time.

A join operation adds a member to a community. Non-members can read most communities but cannot post.

High-level design

A post service owns posts and comments. It writes the records and reads them back by community and by thread.

A vote service owns votes and scores. Scores live in sharded counters, so one hot post cannot overload a single counter.

A page builder assembles community pages. Hot pages serve from a cache and rebuild on a short cycle.

A home builder mixes pages from joined communities. It reuses the same post summaries as community pages.

Moderation actions write to the same records. A removed post is flagged, not deleted, so an appeal can restore it.

How a community page runs

The page builder reads the community's current order. The order is a list of post IDs with scores.

Post summaries load in one batch for the page. The reader sees titles and scores first, not full threads.

Comments load when a post opens. The first level loads at once, and deeper branches load on request.

A cached page can lag the newest votes by seconds. Readers accept that lag, and a voter sees their own vote at once.

Deep dive: vote counting

A vote is a small write with a big shadow. It changes a score that orders a page many readers are watching.

One voter, one vote is the hard rule. A second vote from the same voter replaces the first, and the score moves once.

Retried votes must not count twice. The vote record is the guard, one record per voter and target, updated in place.

Score writes shard by target ranges and by hot targets. A viral post gets its own counter shards, summed at read time.

The score is a count, not a log replay. The vote records stay stored, so a wrong score can be rebuilt.

Deep dive: order and age

Score alone would freeze a page. An old post with a huge score would sit on top forever.

Age pulls scores down over time. A new post needs far fewer votes to pass an old one.

Communities can also sort by newest or by top of the day. Those orders reuse the same records with different sorts.

Comment order follows score with the same age pull. The strongest replies rise inside each branch.

Deep dive: abuse and moderation

Spam and vote rings arrive with open voting. A vote ring is a group of accounts voting together to lift a post.

Rate limits slow new accounts' votes. Limits rise as an account ages and behaves.

Moderators remove posts and comments for their community. A removed item leaves the order at once and shows a plain removal note in its thread.

A spam filter component reads new posts and returns a verdict. It takes the post and the account history as inputs.

Evaluation and trade-offs

Sharded scores trade exact instant totals for write room. A score can trail the true count by a little during a burst.

Cached pages trade freshness for read cost. Community pages are read far more than they change.

One vote per voter trades anonymity for fairness. The service must store who voted, and it guards those records closely.

Age pull trades respect for history against a living front page. The chosen balance keeps new posts able to rise.

Reddit in numbers

ItemFigure
Communities100,000
Posts and comments a day100,000,000
Posts and comments a second1,157
Votes a day1,000,000,000
Votes a second11,574

Exercise

What stops one voter from counting twice on the same post?