Reputation: 1593
I am building a e-ticketing site for buses . I am facing a problem here : When the user books tickets with seat number,I have updated the database with their seat numbers . Now I want to know what if he closes the window and selects not to book .Should I expire his session after a interval of time
Upvotes: 0
Views: 415
Reputation: 151674
While the solution of @Gigi is a reasonable one, it's not complete.
You should somehow reserve the seats a visitor chose, otherwise another visitor, visiting at the same time, might reserve the same seats.
You could set a time, for example ten minutes, for which the seats stay reserved to the visitor who reserved them first. During this time, that visitor can complete the reservation (i.e. enter payment and delivery data), at which point you update the appropriate fields to indicate the seats they represent should not be freed again since they now "belong" to that customer.
You could run then run a delete job every now and then (for example on every page view, or prior to every check for available seats, or perhaps through a cron job) that frees seats that have been reserved more than ten minutes ago but whose reservations have not been completed.
Upvotes: 0
Reputation: 1169
This is an issue which often crops up with ticketing and retail sites. The dilemma often experienced by users is that they buy an item (in low stock) or book a particular seat only to find that the resource is no longer available because another user clicked 'Confirm' before they did...
With an eye to keeping track of resources which are in the process of being purchased it is good practice to implement a temporary 'temp_transaction' database table which your code can consult to determine if a user is in the process of booking, say, a particular seat.
Once payment, vetting and validation on the temporary data has been made then a commit to the main 'transaction' table can be made and the 'resource' (seats) table updated with definitive data.
This approach enables better accounting of concurrent transactions as well as point-in-time auditing of user activity and/or resource status.
Upvotes: 1
Reputation: 29481
I would keep his choices in the session and commit to database only once he confirms the booking.
Upvotes: 4