In social apps, comment sections, or even blogs with active community submissions, it’s often not enough to simply show the latest or most upvoted posts. You want content that’s both popular and fresh to rise to the top. That’s where a hot score algorithm comes in.
In this post, we’ll walk through a popular hot score formula and how to use it to rank your feed dynamically:
score = (upvotes + 1) / (timeSincePostedInHours + 2)^1.5
What Is a Hot Score?
A “hot score” balances recency and popularity. A new post with a few upvotes can outrank an old post with many — because it’s trending now. As time passes, the score decays, letting newer, more engaging content take the lead.
The formula:
hotScore = (upvotes + 1) / Math.pow(timeSincePostedInHours + 2, 1.5)
+1
ensures posts with 0 upvotes still get some rank.+2
in the time component prevents division by 0 and slows decay a little for very new posts.^1.5
controls how aggressively older content decays — this can be tweaked.
Implementing in JavaScript
Let’s say you have an array of posts with createdAt
and upvotes
. You can compute hot scores like this:
function calculateHotScore(upvotes, createdAt) {
const now = Date.now();
const timeDiffHours = (now - new Date(createdAt).getTime()) / 1000 / 60 / 60;
return (upvotes + 1) / Math.pow(timeDiffHours + 2, 1.5);
}
posts.forEach(post => {
post.hotScore = calculateHotScore(post.upvotes, post.createdAt);
});
posts.sort((a, b) => b.hotScore - a.hotScore);
This allows you to serve a feed where content is always evolving and never completely stale.
Real-World Use Cases
This type of ranking is great for:
- 🚀 Reddit-style forums
- 💬 Comment sections on blog posts
- 📸 Social content like photo or meme feeds
- 📰 News aggregators with voting
It keeps things moving and encourages regular check-ins.
Backend Integration Tips
If your data lives in a database like MySQL or PostgreSQL, you can:
- Calculate the hot score on the fly in a SQL
SELECT
. - Create a view or generated column with the hot score.
- Sort your queries using
ORDER BY hot_score DESC
.
Example in SQL:
SELECT *,
(upvotes + 1) / POW(TIMESTAMPDIFF(HOUR, created_at, NOW()) + 2, 1.5) AS hot_score
FROM posts
ORDER BY hot_score DESC
This works well for small-to-medium feeds. For large systems, precomputing scores periodically can improve performance.
🏁 Final Thoughts
The hot score formula offers a sweet spot between new and popular — essential for any dynamic content system. It’s easy to implement and tweak, but powerful enough to keep your feed buzzing.
Next time you’re building a content feed, skip the “most recent” default and try this smarter ranking approach instead.