title: Shopping cart and stock management
body: <p>I am currently building an ecommerce site with PHP/MySQL.  Recently, I have been working on the Shopping Cart integration.   The client wanted to ensure that stock was available to potential buyers, so I created a stock management system.  The shopping cart works as follows:</p>
  
  <ul>
  <li>Client adds a quantity of an item to
  his cart.</li>
  <li>Item quantity is reserved from
  available stock in the database.</li>
  <li>No one else can purchase reserved
  stock.</li>
  <li>Stock remains reserved until client
  processes order - where stock is then
  removed from database.</li>
  <li>If client abandons his cart, stock remains reserved.</li>
  <li>If another client wishes to buy an item, but only available stock is reserved by another client, then the client can steal the reserved stock if it has been inactive for 20 minutes.</li>
  </ul>
  
  <p>My question is, what are best practices for this kind of scenario?  Am I doing this correctly?  The main thing is that the client does not want to sell stock that he does not have.  </p>
  
  <p>I am looking to have a discussion on how to improve the functionality, or what others are doing to accomplish this.</p>