Hello guys.
I have encountered an issue with the storage system. What I am trying to achieve is consistent bucketed leaderboards. Players should be assigned a bucket when they first play a game. The bucket data for each user is saved as an object in storage with keys CollectionKey: "leaderboards-users" Key: "leaderboard_id:bucket-data" for each person. The leaderboards also have bucket objects in the storage. Each leaderboard has a bucket holder, which holds the names of buckets assigned to leaderboards, and for each bucket, there is an object in storage that holds all users assigned to the bucket.
The problem is that when multiple people play games, when the user count increases, the chance of a race condition rises significantly. I have tried using the optimistic concurrency that the storage provides, but I haven’t been able to make much progress since there are a lot of edge cases (roll-backs and so on). Aside from that, I’m assuming retrying numerous times is not intended, plus it makes the code hard to read and follow.
Are there any simple solutions for this problem? I could use a mutex lock, but that seems to be heavily discouraged, and I’m not sure what would happen to the lock when running multiple Nakama instances in a cluster.
Also, I have thought of introducing a queue that responds to these bucket assignment requests, but that solves the last concurrency issue and introduces another.