0

I'm implementing a events booking site. From the shop point of view, the seat must reduce from database only when the seat was actually booked to the customer.

My question is about concurrency. For example, suppose there is a event whose available seat quantity is 1.

If 2 users are trying to purchase the same event seat at the same time, when one of those customers has successfully payed for the seat I want the second customer not to be able to pay for the seat because the seat is already booked.

Is it possible to make such a reservation so that other customers cannot book?

SNJ
  • 11
  • 6
  • 1
    yes sure you could. In your database query check for seatsLeft `insert into booking values (...,...) where seatsLeft > 0` you just need to check the number of inserted rows and then display a proper message to the user. – Multithreader Jul 04 '13 at 10:28
  • see http://stackoverflow.com/questions/7455726/handling-the-concurrent-request-while-persisting-in-oracle-database – Kevin Burton Sep 13 '13 at 14:58

1 Answers1

1

If your database does not guarantee you such concurrency support (and I am not an expert on those), I would suggest implementing a special internal service for your application which would be responsible for booking seats.

All asynchronous booking requests would be put into a synchronized queue, which would be consumed by the BookingService. Then the result message would be sent to the issuer.

That way, with a single booking entity, there will be no races possible and therefore no double booking.

Dariusz
  • 21,561
  • 9
  • 74
  • 114