I am developing an android app kinda random chat.
i have users structure in realtime database which is created whenever a new users login with username.
Database structure is as below.
When user click search button the status changes to searching and i am getting all the users whose status are searching at the same time and randomly match 2 of them. Finally change the status of both users to matched and create a room for those users.
But I stucked at this point. For an instance, when 3 users click search their status turns to searching and i randomly match them. But when i read the status as searching, the other user may be matched already. I can not assure multiple writes to database.
I also used Google App Engine Servlet but no luck.
I wonder is there any method to handle multiple updates of the same field in a queue or lock the field for a user who first accessed?