Best practice for releasing inventory in a database

╄→尐↘猪︶ㄣ 提交于 2019-11-30 14:40:34

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.

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.

If I understand this correctly, it sounds like you should be encapsulating the different steps into a single transaction that rolls back or suspends, if not completed in a timely manner - i.e. the 20 minutes you have mentioned. That way you could lock and unlock line_items records without having to add them back and forth.

It also sounds like you need to think about how you define an 'order'. You probably need to introduce some more steps. The process of going through an order is 'reserving', only when payment is made is it confirmed. That way you could release stock to 'reserving' (over reserving is OK) and the first person to make payment gets the order. The others fail - they should have been quicker!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!