My application is a game where I need each user to be able to create a unique, natural number ID code that can be bijectively converted to a "short string" the same way a url-shortener works. The "short string" part is very important to the game.
I thought about creating a child node with an auto-id key that stores the natural number index & short string and another child node that contains the natural number as the key and the previous auto-id key.
I'm worried about having a race condition in the unlikely event that two users create a new ID at the same time. Ideally, I'd like to be able to increment the IDs starting at 1000 to keep the short strings very short.
Does anyone know a good solution to this type of problem using firebase-database?
I want to keep the "short strings" under 6 characters in length and only use numbers, capital letters and hyphens. (so a 34 character alphabet, ommitting 1s, ls, Os and 0s for clarity)
Maybe this is not possible and I will have to use a 50 character alphabet to generate a random number and add it to every key.
One idea was to check the current highest key and generate a random number to add to that, but there is still no guarantee two users won't get the same number.
So far the only other idea I have to possibly prevent a race-condition if two users attempt to generate a new key at the same time is keeping an internal list of online users and in the child nodes of each user, create the keys and having a delay before posting to the database....requiring the users to check with all other users' requested keys.
This last idea seems convoluted and prone to errors, needing code to check the list every time a user reconnects in case they lost their connection last time they were online.