views:

13

answers:

1

For online ordering of concert seats or airline tickets, do we need Record Level Locking or is Transaction good enough?

For concert ticket (say, seat Number 20B), or airline ticket (even with overbooking, the limit is 210, for example), I think the website cannot lock any record or begin transaction when showing the ticket purchase screen.

But after the user clicks "Confirm Purchase", then the server should Begin a Transaction, Purchase Seat Number 20B, and try to Commit.

If another user already bought Seat 20B in a previous transaction, then it is the "Commit" part that the current transaction will fail?

So... we don't need Record Level Locking? Do Transactions always go serialized (one after another), so that's why we can know for sure there is no "race condition"? In what situation is Record Level Locking needed then?

A: 

Before Inserting the Row You might Check where entries with same SeatId exists. If exists roll it back otherwise Insert the Row and Commit. I am not even Cofident and I think If the service is quite busy you probabbly need locking before starting the insert operation.

However There Is a Exciting Second Option.

You maintain a showId and seatId make an index with this two. and create an unique Constraint on this Index. Now Start the Transaction with any locking. if duplication exists. it will obviously fail due to unique constraint. and commit will be unsuccessful.

Neel

related questions