Ask HN: How often does HN recalculate rankings?
The HN ranking algorithm is well-known (see: http://amix.dk/blog/post/19574). My question is: is the rank of every single post updated at some interval? It would seem that, in some way, this has to happen, otherwise items that are growing obsolete (on account of the gravity of time) would not move down as they should. However, it also seems impractical and prohibitively costly to constantly re-rank every single item. Is the idea that time has such a gravitational effect that HN only needs to fetch all posts where the timestamp is < 2 weeks ago (or whatever) and re-rank only THOSE items since the ranking of a post submitted 2 weeks ago and one submitted 2 months ago will both be approaching zero (thereby limiting reranking to only a small subset of all posts)?
5 comments
I'm not sure how HN does it specifically. In a version of our app, we had scoring which was initially modeled after Reddit's algorithm (http://amix.dk/blog/post/19588). A server task updated the scores for every item every hour. We could have limited how far back we went, but had no need in our case given that the amount we indexed was within reason. We'd add or subtract from the score based on a set of rules that considered a number of factors including posted date, number of votes and number of comments. We had an admin tool for assigning more or less weight to the various factors.
The server does it in a background thread every few seconds. It limits this to the stories that are in memory, but it also (on startup) makes sure that all recent stories are in memory.
There's probably some type of lower bound on the overall score that they use rather than just time. This would be one limit, also updates could be prioritized based on time. So newer posts (or more highly scored ones) would be scheduled to be updated more often.
http://www.righto.com/2013/11/how-hacker-news-ranking-really...
You might expect that every time you visit Hacker News, the stories are scored by the above formula and sorted to determine their rankings. But for efficiency, stories are individually reranked only occasionally. When a story is upvoted, it is reranked and moved up or down the list to its appropriate spot, leaving the other stories unchanged. Thus, the amount of reranking is significantly reduced. There is, however, the possibility that a story stops getting votes and ends up stuck in a high position. To avoid this, every 30 seconds one of the top 50 stories is randomly selected and reranked. The consequence is that a story may be "wrongly" ranked for many minutes if it isn't getting votes. In addition, pages can be cached for 90 seconds.
You might expect that every time you visit Hacker News, the stories are scored by the above formula and sorted to determine their rankings. But for efficiency, stories are individually reranked only occasionally. When a story is upvoted, it is reranked and moved up or down the list to its appropriate spot, leaving the other stories unchanged. Thus, the amount of reranking is significantly reduced. There is, however, the possibility that a story stops getting votes and ends up stuck in a high position. To avoid this, every 30 seconds one of the top 50 stories is randomly selected and reranked. The consequence is that a story may be "wrongly" ranked for many minutes if it isn't getting votes. In addition, pages can be cached for 90 seconds.