Filtering users for Bucketed Leaderboards

Hi!
I’m a bit confused on the best approach to user filtration for bucketed leaderboard. The basic idea is to select users based on user’s level. Nakama’ proposed strategy is to overscan users, meaning if you need 30 users bucket, you should grab, say, 300 and filter them out. Is it the way to go?

Our users will have 10 levels max. Player level is written into user’s metadata. We need 30 people to be in a cohort or bucket. So, what I’ve done so far is:

  1. Entering a cycle of 2 iterations
  2. In that cycle I grab 30*10 random users (nk.UsersGetRandom)
  3. Iterate over each user, get his metadata, extract level, compare to condition, append to cohort
  4. If bucket length is 30, exit cycle

So far, processing 2 iterations of this cycle takes about 30 seconds (case, when no other user have that level). This approach seems a bit straightforward, and might lead to some timeouts or just “too long to wait”.

One of the ideas is to create leaderboard per each level, something like tiered leagues, and grab people of needed level from there. What I need is to keep records of how many entries in each leaderboard, so I can get random people around pivot, which would be a leaderboard rank. But something seems a bit off here.

Hello @McPeterson

The approach with the steps you describe seems ok to me, I find it very odd that it takes 30 seconds to complete, unless I misunderstood.

Is it taking that long because it can’t find enough players to fill the cohort?

There’s an alternative approach where you’d use Storage Search, so you’d need to have a storage object per user with some metadata (level, etc), which you’d also need to update on level changes, and search through the index for your cohorts instead of UsersGetRandom.

Hope this helps.