Rank of post in Reddit is based on Up-Votes and Down-Votes and Age of the post. As per the Reddit Source Code on Github, The ranking algorithm was updated on January 12, 2014. This algorithm keeps interesting  articles in front page. In this article I am going to explain how to implement this algorithm with SQL

Reddit Ranking Algorithm

cpdef double _hot(long ups, long downs, double date):
    """The hot formula. Should match the equivalent function in postgres."""
    s = score(ups, downs)
    order = log10(max(abs(s), 1))
    if s > 0:
        sign = 1
    elif s < 0:
        sign = -1
        sign = 0
    seconds = date - 1134028003
    return round(order + sign * seconds / 45000, 7)
score = upvotes - downvotes
date = Age of the post (Submission Time)
Simplified math equation of the algorithm look like this. 
f(score,age) = log10(score) + (sign)(age / 45000)
sign = sign value is based on score. if score is greater than zero then sign is +1 else sign is -1 

Database Design

We need minimum 2 tables to implement this algorithm.
reddit_post - To maintain rank and age
reddit_vote - To keep track of user votes for posts

Create reddit_post table

create table reddit_post (
 postid varchar(20),
 rank double,
 primary key(postid)
postid - Unique ID of the post
rank - Rank of the post
ctime - Age of the post

Create reddit_vote table

create table reddit_vote (
 postid varchar(20),
 user varchar(20),
 vflag integer,
 primary key(postid,user,vflag),
 foreign key(postid) references reddit_post(postid)
postid - Unique ID of the post
user - User ID
vflag - vote flag ( +1 for up-vote and -1 for down-vote)

Insert into reddit_post

insert into reddit_post(postid, rank) values('post1',3.1029353) 

Insert into reddit_vote

If user up-voted the post then insert 1 for vflag
If user down-voted the post then insert -1 for vflag
insert into reddit_vote(postid, user, vflag) values('post1','srinivas',1) 
insert into reddit_vote(postid, user, vflag) values('post1','srinivas',-1) 

SQL query to Get age

select ctime from reddit_vote where postid = 'post1'

SQL query to Get score

select sum(vflag) from reddit_vote where postid = 'post1'

Calculate rank

  1. Find age of the post by using above SQL query
  2. Find score of the post by using above SQL query
  3. Calculate sign ( If score is greater than 0 then sign is +1 else sign is -1)
  4. Now calculate the rank of the post  f(score,age) = log10(score) + (sign)(age / 45000)


  1. This comment has been removed by the author.

  2. I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! Buy Reddit Upvotes

  3. I really like your take on the issue. I now have a clear idea on what this matter is all about.. posizionamento sui motori di ricerca

  4. Carpet comes in different components and reductions that suit different wants. Whether you might be shopping to get a kids room or even a little-used conventional area, you will find a sort that works to suit your needs.Carpet Cleaning Hamilton

  5. Speaking of vacuum clearer, in the modern day scenario, just about every household has got this machines. It can help families cleanse their dwellings. It is cleaning the painless and swiftly way. Have you wonder how has it been to live wthout using vacuum clearer Victoria carpet cleaners

  6. If you're an entrepreneur looking to purchase a business or perhaps a franchise you should have an awareness of the actual model along with the options these days. This evaluation will describe some tips of the actual franchise Chem Dry Rug cleaning.Metro ChemDry

  7. I am sure you see the trend here... Commercial Mortgage Financing can be used in practically any industry for any kind of commercial property. Speak with your Business Finance Broker when you are ready to invest in a Commercial Real estate opportunity. finance types

  8. The laws of nature are just as they treat every specie (and not only man) with equality. In a jungle, every specie gets its due share of food, air and water which enable them to live a dignified life without being dependent on any other creation. Nature makes no distinction between one specie, and the other as all species are the children of the same God. law information

  9. Real estate shareholders live in addition to die by means of their chance to add importance. With not any added importance, there usually are no gains. This applies with almost any business, but what makes real estate a really great business as well as a great investment decision, is the volume of ways you can contribute value and benefit from big gains. realestate valley

  10. Insurance can be synonymous to a lot people expressing risks involving losses expected coming from a supposed car accident. Here, the price of your losses are going to be borne by the many insurers. insurance guider

  11. Discomfort heard this argument intended for spending far more now with quality just to save money in the future. But why not consider the impression your purchase has on the earth, shouldn't shopping ethically participate in the talk too? services expert

  12. Health fitness ideas also suggest that vices ought to be stopped. Smoking predisposes someone to vascular conditions for example arteriosclerosis as well as heart illnesses. Alcohol consumption do not need to be removed but ought to be limited in order to 30 jiggers each day only. Alcohol nevertheless has many benefits such because vasodilation. These are are just some of what Health fitness ideas recommend health improve

  13. Traveling, for individuals with disabilities, is extremely hectic, particularly when they get to the airport terminal. They face the process of obtaining proper info and instructions. This is actually further aggravated through the huge number of individuals traveling as well as long lists. In international airports, there tend to be attendants which are supposed for carrying on the needs of these travelling along with disabilities. safe travel guide

  14. I know you start to see the trend the following... Commercial Mortgage loan Financing can be utilized in almost any market for almost any commercial house. Speak along with your Business Finance Broker if you are ready to buy a Commercial Real-estate opportunity. financial grow

  15. Many of us have heard your argument pertaining to spending additional now in quality to avoid wasting money after. But why don't you consider the result your purchase is wearing the entire world, shouldn't shopping ethically join in on the conversation too? shoppin guide

  16. You can find all kinds and forms of fashion blogs because internet is brimming with them. It can mention the luxury of wearing lanky jeans around boyfriend skinny jeans or precisely how pink takes the best place of dark-colored plus the many extras. Because you go on-line, you is certain to get your fill in the latest popular trends through fashion blogs. online fashion shop

  17. Well, you can scrub the grout with white vinegar and an old toothbrush, but it's a job that you'll end up doing every couple of days. (Plus, the acids in the vinegar erode your grout.) Visit this link: https:howtoclean.info

  18. Excellent Post as always and you have a great post and i like it thank you for sharing

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    สมัครสล็อตออนไลน์ >>> goldenslot
    สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย

  19. This is cool post and i enjoy to read this post. your blog is fantastic and you have good staff in your blog. nice sharing keep it up. expertise

  20. Great article Lot's of information to Read...Great Man Keep Posting and update to People..Thanks Page Rank

  21. Our blog outreach services help companies form relationships with influential bloggers in their industry.Reaching out to blogs and brands within your industry is a time-consuming and difficult process, but one that is necessary to expand your network and find new opportunities. https://www.thewebfuel.com/

  22. Your blogs are amazing. Keep sharing. I love them Are you also searching for urgent assignment help? we are the best solution for you. We are best known for delivering the best urgent assignment help.



Popular Posts