I am building a community that operates on reputation similarly to SO. I need to keep a leading board of the users with the most reputation. Preferably by percentage (for example top 5% of users).
I am using cloud firestore. Currently the best option I can think of, is that when a user log in I make a read query for users, order the results by reputation and limit it to whatever 5% of the current amount of users is, and then from the results I create the leading board.
The problem though is that this could lead to huge amounts of reads as the community grows. If for example the community has 100k members, then every login the user end needs to read 5k documents just to get the leading board.
The other option I can think of is to have one document of the leading board and whenever someone's reputation changes then I edit that document. But this would lead to many writes, as just like SO reputations would be changing quit often.
*its important to mention: I need the leading board just to grant certain permissions to users on it that others don't get. So other than knowing if the user is part of those 5% or not there's nothing else I need from it. There's not an actual leading board page where you can see the users' profiles or anything like that.
Can anyone suggest better ways of approaching this?