How to build a trending post algorithm?

What is the best way to build a trending post filter? I want to filter posts by the number of upvotes, comments, and other interactions like that. How could i go about doing this?


upvotes as numbers you can add a filter to your displaying repeating group: data source > Sort by: upvotes > descending = yes

same for a list of comments, pretty straight forward stuff

I understand the concept of filtering by upvotes but was thinking of more of a sort of rate of upvotes sort of thing.


a post may already have 100 upvotes but only getting one or two people upvoting everyday.

Another post may only have 5 upvotes but is gaining them at a much faster rate of 5 or 6 a day.

How can I sort these in this kind of way?

I think you should have a column that is auto-updated (maybe every night) with whatever formula you have in mind to calculate “trending”. This backend workflow should be just running for the certain posts of course to reduce the size of the input.

But as you said, it is not purely based on number of something. You should take the velocity of things into account as well (i.e., a 2-comments topic with 100 new comments in one day should be more trending then a 1000-comment topic with just 3 new comments in one day).

You can find more data when you search like how reddit ranking algorithms work and similar queries for hackernews, facebook etc

oh now i understand. So this is what i would do:
i would create another data type for post called “rate” as a type number,
everytime a post gets a upvote or another comment, that rate is incrised by 1,
then i whould fillter my trending posts based on posts rate. You can also make a upvote or a comment reaward more rate as you like.

Now if you need to reset this rate, you can schedule a weekly or a monthly action to reset all posts rates to 0.

thanks for the help, i havent really found anything useful that can help and also finding it hard to sort by the ‘rate’ like @jefeoliveira22 suggested

how can i ensure that this isnt just the same as the number of upvotes, as i want to make sure that this is a constantly dynamic thing for past 24 hours or past 7 days etc.

What if i did something like sort by rate/24hours would that work?

because rate is going to be a SUM value of all interactions (upvotes, comments, clicks?) wich will determ the post relevancy overall. And also as i mentioned, each interaction can have its own value, e.g: a comment can give more rate than a upvote. Social media marketing work like this, comments and shared posts give way more relevancy to the algorithm than a post like. Also this feels like a lightwiehgt solution on your database’s shoulders.

As for hour/rate like 24h, you can either schedule a backend workflow to reset all posts rate, or you can manually set up to reset all posts rate after the next registered iteraction past the last defined date/time, and you can track this by adding another data type of date/time range. Both options seems to work exactly the same imo, its up to you

1 Like

Also potentially instead of resetting to 0 you could have an arbitrary number they get decreased by each 24hrs, so that very popular posts from a few days ago can still be floated to the top etc, but still give new posts a chance.

1 Like

Yep that’s a great idea :slight_smile: just dont forget to add a conditional so values cant go below zero :stuck_out_tongue:
also i forgot to mention (if you didnt get right), each interaction will incrise its rate based on EACH interaction, so:
IF the post gets a comment +5 rate
IF gets a upvote + 2 rate
and so on.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.