Context:
I have built a viral waitlist feature so that when a user signs up they are assigned a rank in my waitlist. If they refer a friend they move up the waitlist, see screenshot below:
I calculate the waitlist rank by doing a search for all users who are currently marked as being on the waitlist, taking a count and then adding 1:
Problem!:
When multiple users are signing up at the same time or just a few seconds apart, they all get the same waitlist rank assigned to them!! I am guessing that doing the search for users on the waitlist, taking the count and adding 1 is taking too long.
How can i make sure that it correctly assigns a unique number for each new user who joins the waitlist?
Thank you so much for your help!!