Concurrency: How to limit the edge count to a given number?

I found a solution that might work just fine and I cannot think about a scenario where it fails.

Instead of using timestamps, I will use dGraph new UIDs as tokens for subscribers to games and only keep the N first tokens based on the UID value.

Now, N players (generating N parallel requests) will each:

  • get an available game
  • create a token (connected to the game and themselves)
  • get the game node again with all tokens (and their connections to players)
  • sort all tokens based on their UID
  • check if their own token is at a position that fit into the game maximum capacity
  • if not they remove their connections to the game and try the whole process again

Concurrency