释放数据库中库存的最佳实践
我正在构建一个售票应用程序,用于跟踪门票库存,并在特定门票售完时停用它们。
我想知道当订单中途放弃时将库存释放回商店的最佳做法是什么。
当前流程:
- 用户将
items
添加到order
中作为line_items
,并且order
在成功付款后标记为已完成 items
有一个quantity_available
,它是根据其line_items
更新的,- 我定期扫描
orders
中没有任何操作的orders
20 分钟,删除这些订单的line_item
并更新quantity_available
感觉我错过了一些东西。其一,我失去了详细审查放弃订单的能力(我仍然有任何付款/拒绝等......但没有行项目)。如果用户在 21 分钟后尝试恢复旧订单,他们将不得不重新开始。
相反,它会占用库存 20 分钟,当一场演出几乎售完时,这可能会导致我们的销售损失。
任何见解将不胜感激。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
引入一个不同的标签怎么样:保留什么的。在处理订单时,您可以将票标记为保留,这会减少总库存数。但您现在确切地知道有多少张票处于待定状态。
在 20 分钟的长订单期间,如果现有商品数量非常少或已空,您可以向用户发送更新。 “订单已经停滞了5分钟。门票销售进展很快,请尽快完成订单,以确保您的门票仍然可用。”
您还可以告诉潜在买家,可能有 x 数量的预订门票可供使用,因此他们应该回来查看或进行其他操作。也许他们可以注册,以便在保留的票返回到系统时接收电子邮件。
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.
我想知道为什么你们会根据未处理的订单占用库存?我正在考虑新蛋网和亚马逊等热门网站的运作方式。我可以创建一个购物车,并且它会无限期地存在。但它对我的库存没有任何作用,它只是数据库中的一条记录。有了 Newegg,我可以在几个月后返回该网站,而我废弃的购物车仍然在那里(这在过去对我来说非常方便)。
您仅在用户完成订单时修改库存。这还允许您运行有关废弃购物车的报告,因为您只需使用上次修改日期与订单完成情况相结合即可确定哪些购物车被废弃。
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.
如果我理解正确的话,听起来您应该将不同的步骤封装到一个事务中,如果没有及时完成(即您提到的 20 分钟),该事务将回滚或暂停。这样您就可以锁定和解锁 line_items 记录,而无需来回添加它们。
听起来您还需要考虑如何定义“订单”。您可能需要引入更多步骤。办理订单的过程是“预订”,只有付款才算确认。这样您就可以将库存释放到“保留”(超过保留是可以的),并且第一个付款的人会收到订单。其他人失败了——他们应该更快!
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!