5

This is a pretty generalized question which I am asking.

Scenario 1

I have a product 'Pen' which has a quantity of 1. Now 2 users a and b has come to buy the product.User 'a' clicked on buy now and has started the payment processing and once the payment is completed the order for the product will be created and I would reduce the quantity to zero and user b will see the product as 'Out of stock'. This a more macroscopic explanation.

Scenario 2

User a is making a payment and in between user b also clicked on pay and proceeded the payment process. user a completed the order and the quantity was reduced to zero.User b completed the payment and the order failed!

How does this problem is managed by e commerce sites? Is it like, when a user proceed for the payment of a product, is the quantity is reduced to zero and once if that order fails (due to a payment failure), does the quantity is incremented back so that other user can buy it?

How is this condition managed?

1

There are many specific strategies for handling this. Generally speaking, mostly it comes down to either using transactions of some sort (e.g. in the db, or locking objects in memory), or, using compensation strategies. I would say that many business domains use a combination of both.

The concert domain typically allows making reservations, which are good for a few minutes, during which the order can be placed. The reservation mechanism may use transactions, so the inventory goes from free, to reserved, to purchased (or back to free). They won't attempt to charge you unless the reservation succeeds, but if your payment fails, they get the inventory back shortly.

Airlines this same problem, and also use reservations, but typically have a wider distributed computing problem in that they allow partner airlines and travel agents to also sell tickets. As a result, they may end up overbooking a flight, and then they offer rewards for someone to give up their seat. Especially in the old days, they would distribute some of the inventory in advance to the third party sellers, to try to help with the distributed computing problem.

An E commerce site may try to inform you of low inventory situation when you are viewing the item. E commerce sites sometimes fail (inventory was just plain wrong, or, too much demand for some item), by taking payment when there is no inventory. Then they apologize and return the payment. Like the airlines, they may offer some additional compensation to the unfortunate user.

Fundamentally, in business, one expects to have agreements (i.e. for purchases), that sometimes fail and need to be dealt with. Failure could be at inventory, or the product get damaged/lost in shipping, or the product may be defective. Handling these things typically makes use of compensation strategies. One point of business operation is to tune these strategies (to maximize profit, maximize customer retention, etc...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.