I have one question lets say I am creating a leade...
# random
e
I have one question lets say I am creating a leaderboard microservice then I am not able to understand what data should I store in actual DB and what to store in redis? will both of them store exact same data? I was referring this article https://aws.amazon.com/blogs/database/building-a-real-time-gaming-leaderboard-with-amazon-elasticache-for-redis/
l
@echoing-computer-87366 when we did this for leaderboards, we stored only tabular data (ie only the columns that we showed in a table view inside the game) in redis. We had a global and a friends leaderboard with different columns that we would show. Ours was a multiplayer racing game and we had to show updated stats as soon as the race got over - so we would store only the data we needed to show in the table in redis. We used Mongo for all other data and the player data was substantially larger to what we pushed in redis. But Mongo was the source of truth. And redis has like 10% of the data that Mongo had on the player. Hope this helps.
e
I was thinking of this approach let me know if it is wrong. 1. So I will store score, player id, rank in redis sorted set data structure and all other player info in MySQL 2.  I will store player details in actual DB like MySQL or mongo etc. Then for leaderboard microservice I will push all the players into leaderboard for a particular game with initial score of zero for all players. Now I will use ZINCRBY ZDECRBY and ZUPDATE which is available for redis sorted set data structure. 3. So in this way I will be only storing score, player id and rank  these 3 fields in redis store which will be available on leaderboard for display and to get top X players I will use ZRANGE which is available in redis. Now these updates in leaderboard will happen real time as these operations in redis are O(1) operation so it will be very fast. All this data will be in redis only and rest all the data will be in DB is this correct? Let me know your thoughts on this. Just wanted to confirm separation of data
l
Hey Aditya. I have not used Redis in a bit - so I am assuming the commands are correct. The other thing I am not a 100% sure about is the storing of
rank.
I am assuming calculating Rank and storing it would be a long operation? I’d rather just sort by score and return top 50, 100 etc (whatever you need) which becomes your rank. Unless you have some other way of calculating rank (like an ELO rating or something). Or if you are running some provisional rating system.
e
Yes got it in my case no need to store rank in redis. I have one more question lets say if game duration is 10min then how can I get the highest score of each individual player? In a game of 10min duration a player can have score of 100 at 5min and by the end of the game his score can be different. So how to capture max value of score for each player in given time duration?
l
@echoing-computer-87366 Sorry man. I think that question is too specific and without diving deeper into how your game works, etc. I will not be able to answer it.
e
ok thanks np 🙂