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 anorder
asline_items
and theorder
is marked as completed on successful payment items
has aquantity_available
that's updated based on theirline_items
- I sweep periodically for
orders
with no action in > 20 minutes, delete those orders'line_item
s and update thequantity_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.
line_items
at runtime to get the current inventory available as discussed here. To me that seemed like it would be slow needing to perform that query on every single transaction, and that caching the quantity would be better. Very possible that I'm wrong about that, though. – Siroccoquantity_available
(which should never be adjusted). If you don't do that you can have the case where some script/process adjusted the number but you can't see why - which could lead to over/under sell. FYI I run several such software systems and have not run into the "what if someone wants it but someone else has it reserved and doesn't use it" situation - yet (although I also feared it) – Broad