-2

I want to do movie ticket booking and event ticket booking.

In that how to avoid duplicate booking in short cuncurrency.

I have five seats remaining in my event.

Two user comes both will see 5 seats but only one can book it.

How can I achieve this?

Please help me solve this issue.

  • 1
    Basically: When the users try to book the seats check if they area already booked by somebody else. If they are still available it's ok, otherwise return an error. You would have to use transactions and record locks to ensure that on the database level events can't run in parallel. – thorsten müller Oct 08 '16 at 09:42

1 Answers1

0

Consider how this is done in reality: All users are shown available seats, clicking on one (I am assuming that you have a GUI of some description of course) implies intent to purchase and is then marked as reserved (until purchase is complete or a timer expires / session ends, etc).

Your seats have (in my eyes) 3 states: available, reserved, and purchased.

  • Available seats can be reserved by users.
  • Reserved seats are added to an order and can be purchased.
  • Purchased seats are not available to be reserved.

Clicking on an available seat marks it as reserved, this can no longer be selected by other users. Reserving seats adds them to an order, which when paid for marks the reserved seats as purchased, which now display as unavailable.

In your scenario of two users wanting to book the last seats, it will (just like in reality) be a first come first serve basis. The first user to reserve the seat, and then purchase it, get's the ticket.

You will need further consideration as to how you prevent seats from being permanently reserved and never purchased (as mentioned above) etc.

If you have a web front end, you could consider making these Ajax calls to show a real-time update of seats being reserved.

Dan-Cook
  • 98
  • 4