如何处理库存和并发
有哪些策略可以处理看似常见的有限库存和订单的情况。
如果还剩一件商品,并且两个人同时尝试购买。最后付款的人如何处理?
What are strategies to deal with seemingly common scenario of a limited inventory and an order form.
If there is one item left, and two people attempt to purchase at the same time. How do you deal with whoever submits payment last?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当用户将限量供应的商品添加到购物车时,请将该商品保留一小段时间(例如 15 分钟)。如果他们在窗口内付款,则该物品属于他们,否则将取消保留并将物品返回到池中。 (在保留期间,该项目被认为对其他用户“不可用”。)
据我所知,这是非常标准的技术 - 我已经看到例如,Gilt 就是这么做的。
When a user adds a limited-supply item to their shopping cart, put a hold on the item for a small window of time - say, 15 minutes. It's theirs if they pay within the window, otherwise the hold is removed and the item is returned to the pool. (For the duration of the hold, the item considered "not available" to other users.)
AFAIK, it's pretty standard technique - I've seen Gilt do this, for instance.
根据用例,假设您想要按照先到先得的原则分配库存,并希望确保库存不会出现负数,那么以下方法就可以工作。
Depending on the use case, let's say you want to allocate inventory on a first come first serve basis and want to ensure that inventory does not go negative, then the following can work.