Backendless Support
 
Planned

Leaderboard - current user ranking

Hi there,

In my app i have sort of a leaderboard. I was wondering how i best can get the rank of the current user, when in total there are 100+ users and the user is positioned later than the first 100.

Thanks

Leave a Comment

Comments (6)

photo
1

Hello,

I would recommend creating a custom API service which would perform that calculation. You would either need to run queries to get users sorted by some criteria OR alternatively, run checks in beforeUpdate event handler to see rank the user in real-time.

Regards,

Mark

photo
1

Hi Mark,

Thanks again for your quick response! I am a litle concerned about the performance of such a solution. when, for example, there are 10k users in the leaderboard and a user is places 9500 i need 95 api calls? (100 each time and checking if it contains that user id?).

Are you aware of a backendless project containing a leaderboard? Otherwise a service specifically designed for leaderboards might be a better solution for the leaderboard section of the app.

Kind regards,

Frank

photo
1

Hi Frank,

What is the algorithm for organizing the leaderboard? I assume the users would need to be sorted by some kind of criteria, is that right?

Regards,

Mark

photo
1

Hi Mark,

Currently it is a table containing a username and its score, the query contains a order by desc.

Kind regards,

Frank

photo
1

Hi Frank,

Currently there is no easy/simple way to get that value. It would require either going through all the records or maintaining a sorted tree somewhere in memory.

We will consider adding native support for this operation in version 4 of Backendless (currently in Beta).

Regards,

Mark

photo
1

Hi Mark,

Sounds good!

Kinds regards,

Frank