I’m trying to learn how to code a website algorithm like Reddit.com where there are thousands of posts that need to be ranked. Their ranking algorithm works like this (you don’t have to read it, its more of a general question that I have): http://amix.dk/blog/post/19588
Right now I have posts stored in a database, I record their dates and they each have an upvotes and downvotes field so I’m storing their records. I want to figure out how do you store their rankings? When specific posts have ranking values, but they change with time, how could you store their rankings?
If they aren’t stored, do you rank every post every time a user loads the page?
When would you store the posts? Do you run a cron job to automatically give every post a new value every x minutes? Do you store their value? Which is temporary. Maybe, until that post reaches its minimum score and is forgotten?
I would definitely not calculate their rank every time you display them.
A simple, and not so performant solution would be to cache post rankings, and once one post’s ranking changes, you clear or refresh the cache.
That is not ideal, but it is possible.
Another way would be to do as you alluded to: calculate and store ranks in the database (and ideally cache them), and then refresh those rankings using a cron job every x minutes.
Again, these are basic approaches to what you want to do. You can then build on them over time.
The algorithm you choose will most likely be very particular to your needs.
You need to also gauge what kind of traffic your site would be getting, as it would dictate what kind of lengths you should go through to get the right algorithm.