and User B tried to book a slot at 3pm at the same time
My backend will receive the req and it will check whether that seat is available or not in my database
So two request will be sent to db from my server for the user A and B, it will return that seat is available for both users
So server will try to book for both
I am using nodejs as backend so the db op will be async
So how do I prevent this thing ?
Should I use some global variable or something and lock a particular seat so after db operation if the variable is not locked that user can book and the variable will be locked so when other user tries to access that variable it will say the slot is already chosen
How is it stored? Are the "seats" already there(as unbooked) and are they updated as someone books them or are the table rows inserted as the person books them?
Use queueing system, where you process requests one at a time. There are many such libraries Or have a pool of available seats in memory and remove when claimed
When you say in memory what kind of databases are we talking about here? Redis?
Обсуждают сегодня