Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to handle such situation.if two seats are available.10 different people were trying to book tickets for those two seats .then finally seats booking is done for only single person and how transaction is managed.

What I have tried:

i thought its using lock concept as iam not much familier to this kind of scenarios .i hope you would help me.
Posted
Updated 7-Feb-18 22:45pm
v2
Comments
Ziee-M 8-Feb-18 4:36am    
This is actually a concurrency situation. Concurrency occur when more then one transaction tries to update the same row/data.
An exception will be raised if you fall in this case and you have to handle that exception to resolve the situtation.
I cant Give you more details because it totaly depend on the tools you use to access your database (EnityFrame, ADO.net...)
Each one of these handle the Concurrency diffrently.
Just a few searchs with concurrency keyword, and you will find a lot of answers.

1 solution

The record for the seat in the database should have some kind of "locked at" field. When someone clicks the "book" button it will update the "locked at" field with the current time. If someone else tries to book a seat with a non-null locked time they're told someone else is booking it. When the user cancels the booking then clear the field, you could also clear it when the booking is made. The tricky bit is that you then need some form of automated task (SQL agent, scheduled task, windows service, timed event etc) that clears locks that are over, say 10 minutes old and assume the booking was just abandoned.
 
Share this answer
 
Comments
Ziee-M 8-Feb-18 4:57am    
I dont think this is a practical solution, many other users will be blocked while the first one is buying. In addition, the Booking process can take several minutes.
F-ES Sitecore 8-Feb-18 5:04am    
The alternative is to let the other users go through that 7 minute process simply to be told at the last second that someone else got the seat. They might then search for another seat and have the same thing happen so simply abandon your site altogether.
Ziee-M 8-Feb-18 5:10am    
I think you just add a trigger that raise an exception in Database level when no tickets are left. and you have to manage concurency in a hight transaction environement like this one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900