Reputation: 33
I have a case where the booking system need to be implemented in an app. Booking is done for machines. The user can book only if he has the required machine available. For that I have represented the availability count of each machine in the database. So when a user books a machine, it queries the database and checks for availability and only if its available he is allowed to book. But there some sort of error which I encounter. For example say a machine A. It has an availability count of 1 as of now. But when simultaneously two clients try to book A, then surprisingly both their bookings are accepted. This happens like once in 10 times or so. I am guessing this is due to the varying internet speed of each client. But this flaw fails my entire logic. How to fix this. Can anyone please help
Upvotes: 1
Views: 201
Reputation: 598728
Without seeing the minimal code that reproduces the problem it's hard to be sure, but it sounds like you should be using transactions for these operations.
Upvotes: 1