2

If I'm writing a ticketing system, where the customer selects the ticket and I want to lock it for 3 minutes (like ticket master) until they complete their order or time runs out, how could I do this? I want to avoid having a customer abandon their session/application crash and then end up with the ticket locked in the database forever.

I'm using nHibernate for my ORM and C#.

3 Answers3

7

Just have a separate table that holds all current reservations. For example:

**Reservations**
UserID
TicketID
ExpiryDate

This will then not be dependant on sessions. You don't even need to delete expired records, when a new customer queries a ticket find all seats that are available where they dont exist in the reservations table where the expirydate > now.

Avoid more complex systems of timed events and things like that, keep it simple.

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
0

Have a ticket expiry service that periodically unlocks expired ticket locks. Record the expiry time and the ticket (possibly with a session id). The the order could remove this when no longer needed or in case of faliure it will be automatically unlocked.

Chriseyre2000
  • 2,053
  • 1
  • 15
  • 28
0

If you can identify each ticket, you can assign locking information to this ticket with data about user, order, etc and of course - timestamp wich holds time when lock expires.

If another user wants to select the ticket, you just need to check this timestamp to see if the lock has expired.

ULazdins
  • 1,975
  • 4
  • 25
  • 31