A ranked feed has two jobs that pull against each other. It has to be fresh: a post from 20 minutes ago that everyone is upvoting should be near the top now, not tomorrow. And it has to be fair: a dozen accounts run by one person shouldn't be able to push a post to the front page.
In this lab you'll design the voting and ranking core of a community site like Reddit. You'll count a billion votes a day, keep rankings fresh without re-sorting the world every minute, and defend the rankings against people trying to game them.
The brief
Users post links and text into communities (subreddits). Other users upvote or downvote posts and comments. Each community has listings: hot (what's good right now), new, and top (best of the day, week, all time). The home page merges the hot listings of every community a user has joined.
For this lab:
- In: posts, votes on posts and comments, scores, hot/new/top listings per community, the merged home feed, comment ranking, basic anti-manipulation.
- Out: chat, moderation tools, ads, search, notifications, media hosting.
Requirements
Functional
- Users can upvote or downvote a post or comment, change their vote, or remove it.
- A user can vote at most once per item.
- Each community has hot, new and top listings.
- Each logged-in user has a home feed built from the communities they've joined.
- Comments on a post are ranked by quality, not only by score.
Non-functional
- Your own vote shows instantly, and stays shown when you refresh.
- Rankings are fresh: a vote affects listings within about a minute.
- Listings load in under 200 ms at the 99th percentile.
- Rankings are hard to manipulate with fake accounts or coordinated voting.
- Scores everyone else sees can be a little behind, by seconds. Nobody minds that.
That last line is a gift. It means the global score doesn't need to be strongly consistent, only each user's own vote does. Keep it in mind.