How do I design a system where I need to find top N users in the leaderboard and also rank of a user randomly?

  softwareengineering

Let’s say I have 100 million users in the database, and each of them have a reward point associated with it. This reward point is eventually consistent. And we need to rank the users based on this reward point. Now, I know how to find top N users who are having most reward points. Basically, we may have a separate datastore to store top N users at any given point. I can use a heap to keep track of top N at any given point and flush it to the DB. But, what if I need to find the rank of a random user (also users who are adjacently ranked to the given user) from 100 million users? We can’t put all 100 million users into memory for sorting. So, how do we achieve it ?

New contributor

Rahul Raj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT