title: Synchronising c#/asp.net booking application
body: <p>I'm developing an event booking application and am having difficulty figuring out how to manage the booking process. I know about db transactions and a little bit about locking but I have a lot of business rules to validate before a booking can be committed and I'm worried about performance bottlenecks.</p>
  
  <p>Here's a summary of what's going on:</p>
  
  <ul>
  <li>An Event has a maximum number of slots</li>
  <li>A user can book one spot in the Event</li>
  <li>Each user has an account with money in and each event costs a certain amount</li>
  </ul>
  
  <p>Given the above parameters, the following business rules are what I need to validate for a booking to take place:</p>
  
  <ul>
  <li>The user hasn't already booked a spot for this Event</li>
  <li>The user has enough funds to book the Event</li>
  <li>The Event has at least one spot available</li>
  <li>The Event does not conflict with other events the user has booked (not so much of an issue as I can check this when displaying the page and hide this Event from the user)</li>
  </ul>
  
  <p>My main worry is that if I pull all the information from the db up front (i.e. Event, User, Account, and existing Bookings) that by the time I run all the validation and come to commit the new booking, the state of the system will have possibly changed (i.e. someone else has booked the last spot, money has left my account, etc).</p>
  
  <p>If I was to lock the code/database tables around this booking process, then I've potentially (??) got the lock for quite a while affecting other operations in the system and causing performance issues at peak times.</p>
  
  <p>Can anyone suggest an approach whereby I can manage or at least limit these concerns.</p>
  
  <p>I'm building an asp.net app in c# and using sql server 2005.</p>