Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for releasing inventory in a database

I'm building a ticket-selling application which tracks an inventory of tickets, de-activating them when a particular ticket is sold out.

I'm wondering what the best practice is for releasing inventory back into the store when an order is abandoned mid-way through.

The current flow:

  • Users add items to an order as line_items and the order is marked as completed on successful payment
  • items has a quantity_available that's updated based on their line_items
  • I sweep periodically for orders with no action in > 20 minutes, delete those orders' line_items and update the quantity_available

It feels like I'm missing something with this. For one, I lose the ability to review abandoned orders in detail (I still have any payments/declines, etc... but no line items). And if a user tries to resume an old order after 21 minutes they'll have to start fresh.

Conversely, it ties up inventory for 20 minutes which could lose us sales when a show is nearly sold out.

Any insight would be much appreciated. Thanks.

like image 359
Alex Dunae Avatar asked Feb 25 '11 18:02

Alex Dunae


2 Answers

How about introducing a different tag: reserved or something. While an order is processing, you can mark the ticket reserved which decrements the total inventory count. But you now know exactly how many tickets are in limbo.

During your 20 minute long order, if the number of on-hand items is very low or empty, you can send updates to the user. "Order has been stagnant for 5 minutes. Ticket sales are going fast, please complete your order soon to ensure your ticket is still available."

You can also tell potential buyers that there are x number of reserved tickets that may become available, so they should check back or something. Maybe they could sign up to receive an email if a reserved ticket comes back into the system.

like image 70
Nathan DeWitt Avatar answered Sep 28 '22 21:09

Nathan DeWitt


I am wondering why you tie up the inventory based on an unprocessed order? I am thinking of the way popular sites like Newegg and Amazon work. I can create a shopping cart and it will live indefinitely. But it doesn't do anything to my inventory, it's just a record in a database. With Newegg, I can go back to the site months later and my abandoned shopping cart is still there (which has been very handy for me in the past).

You only modify the inventory when the user completes the order. This would also allow you to run reports on abandoned shopping carts because you'd just use the last modified date combined with order complete to identify which carts are abandoned.

like image 40
Jake Munson Avatar answered Sep 28 '22 20:09

Jake Munson