I want to create a backend for a mobile game that includes a global leaderboard in real time for all players, for events that last a certain number of days using the Google App Engine (Python).
Typical uses will be as follows: - The user starts and ends the battle by acquiring points (2-5 minutes for the battle) - Points are accumulated in the player’s account throughout the event. - The player can check the leaderboard at any time. - Leaderboard will return the top 10 players, as well as 5 players just above and below player points.
Now there is no real restriction on the real-time aspect, the board can be updated every 30 seconds, every hour. I would like it to be as fast as possible, without too much cost.
Since I am not very familiar with GAE, this is the solution I was thinking about:
- Each Player object has an event_points attribute
- Using the Cron job, a query to the data warehouse is performed at regular intervals for all players whose score is not zero. The request is sorted.
- The cron job then iterates through the results of the query, writing down the ranks in each Player object.
When I think of this decision, it feels like brute force.
The problem with this solution is the cost of reading and writing for all objects. If in the end we get 50K active users, this will mean a sorted request of 50K + 1, and 50k + 1 will be recorded at regular intervals, which can be very expensive (depending on the interval)
, memcache , memcache, ?
, , memcache , , " " , , .
?