Medium · 12 steps · ~70 min
Design a ranked feed
Votes pouring in, and a ranking that stays fresh and fair.
Posts are ranked by votes and age. Reads are constant and votes arrive in a flood.
Same problem as RedditHacker NewsProduct Hunt
How it works
- Read: show a precomputed ranking.
- Vote: record the vote, recompute scores in the background.
What you'll build
- The API and data for posts and votes
- A system that answers 800 requests a second
- A cached front page within a budget
- A queue and workers that tally votes
- A design for a viral post and a rate limiter against vote bots
- A system that survives a cold cache, a lost server and a lost primary
Steps
- 1Design the API
- 2Design the data model
- 3Handle 800 requests/sec
- 4Cache the front page for $900 a month
- 5Queue the votes at 30,000 requests/sec
- 6A viral post at 100,000 requests/sec for $2,000
- 7How fresh should the ranking be?
- 8Survive vote brigading on $2,200
- 9Survive a cache restart
- 10Lose an API server
- 11Lose the primary database
- 12Deep dive: a retried vote counts twice