Ranking by votes: net score vs Wilson score vs Reddit hot, interactive
Every site with votes has to turn them into an order. The obvious formulas fail in predictable ways: net score lets old posts sit at the top forever, and the upvote ratio lets a post with one vote beat one with thousands. The Wilson score fixes the ratio by asking how good a post is at least, given how few votes it has, and time-decayed scores like Reddit’s hot and Hacker News’s gravity make room for new posts.
The playground orders the same eight posts four ways. Click a post to follow it across the columns, give it votes, and jump twelve hours ahead.
8 posts. Net score puts “Week-old megathread” first, and keeps it there however old it gets. Upvote ratio puts “One upvote so far” first, though a handful of votes is not evidence. The Wilson score ranks by how good a post is at least, with 95% confidence, so “Yesterday’s hit” leads and the post with one upvote ranks last. Hot discounts age, putting “Solid how-to” first. “One upvote so far”, 1 up and 0 down, 6 min old, ranks 8th by net score, 1st by upvote ratio, 8th by Wilson score, 8th by hot.
Click any post to follow it across the four columns and vote on it.
What each formula gets wrong, and right
- Net score rewards size and age: the week-old megathread leads with 3,300, and nothing new can catch it. It also hides controversy: 900 up and 850 down scores the same as 50 up and nothing down.
- Upvote ratio rewards luck: a post with one upvote has a perfect 100% and tops the list.
- Wilson score takes the lower bound of the 95% confidence interval for the true upvote share. One upvote gives a lower bound of only 21%, while 2,400 up and 150 down gives 93%, so well-tested posts lead and small ones must earn their place. Reddit’s “best” comment sort uses it.
- Hot adds the post time to the logarithm of the score: ten times the votes buys 12.5 hours. A solid post from six hours ago outranks yesterday’s much bigger hit. Since every post ages at the same rate, the order changes only through votes and new posts, so it can be computed once per vote and stored.
That last point matters for systems. A score that depends on the current time, like Hacker News’s (points − 1) / (age + 2)1.8, has to be recomputed for every post as time passes, so sites recompute it periodically for recent posts only. Reddit’s hot score is fixed at vote time, so a sorted index such as a Redis sorted set keyed by score stays correct between votes.
The formulas in code
from math import log10, sqrt
def wilson_lower_bound(up, down, z=1.96):
"""'Best' sort: how good this post is at least, with 95% confidence."""
n = up + down
if n == 0:
return 0.0
p = up / n
return (p + z*z/(2*n) - z * sqrt((p*(1 - p) + z*z/(4*n)) / n)) / (1 + z*z/n)
def hot(up, down, posted_at_epoch_s):
"""Reddit's 'hot' sort: ten times the votes buys 12.5 hours."""
s = up - down
order = log10(max(abs(s), 1))
sign = (s > 0) - (s < 0)
return round(sign * order + (posted_at_epoch_s - 1134028003) / 45000, 7)
def hacker_news(points, age_hours, gravity=1.8):
return (points - 1) / (age_hours + 2) ** gravityIn a system design interview
For a feed or comment section, say how scores are stored as well as computed: “Posts are ranked by a hot score that combines log of net votes and post time. Votes go through a queue; a worker updates the post’s counts and score and writes the score to a Redis sorted set per subreddit, so the front page is a range read. Comments use the Wilson lower bound, so new comments with one vote do not jump the thread.” Expect the follow-ups: vote brigading and fraud, hot posts’ counter contention, and personalization on top of the global score.
Read the guide to voting and ranking algorithms or comments and threads, see skip lists for the sorted set underneath and hot keys for viral posts, or watch a strong candidate design Reddit.
Questions people ask
How does Reddit rank posts?
The hot sort adds the logarithm of a post’s net score to its submission time divided by 45,000 seconds. Ten times the votes is worth 12.5 hours of recency, so newer posts rise above older ones unless the older ones have far more votes.
What is the Wilson score?
The lower bound of the Wilson confidence interval for the true proportion of upvotes, given the votes so far. It estimates how good an item is at least, with a chosen confidence, so items with few votes score low until evidence accumulates. Reddit’s best comment sort uses it.
Why not sort by average rating or upvote ratio?
Because small samples produce extreme ratios. An item with one upvote has a perfect ratio and would outrank items with thousands of votes and a 95% approval. Confidence-based scores such as the Wilson lower bound or Bayesian averages correct for this.
Why not sort by net score?
Net score grows with exposure, so popular old items stay on top forever and new items never get seen, and it treats a heavily disputed item the same as a quietly liked one with the same difference. Feeds add time decay; comment threads use confidence-based scores.
How does the Hacker News ranking work?
A post’s score is roughly (points - 1) / (age in hours + 2) to the power 1.8, plus penalties. Because it depends on the current time, scores are recomputed periodically, usually only for recent posts, rather than once per vote.
How do you store a ranked feed at scale?
If the score changes only when votes change, as with Reddit’s hot formula, compute it on each vote and keep posts in a sorted index such as a Redis sorted set per community, so the top page is a range read. Time-dependent scores need periodic recomputation of the recent window.
What is a Bayesian average?
An average rating pulled toward a prior, typically the site-wide mean, by adding a number of imaginary votes at that mean. Items with few ratings stay near the prior; items with many ratings converge to their own average. It is a simpler alternative to the Wilson score for star ratings.