45

I'm designing an e-commerce application and I'm concerned about users occasionally experiencing this:

  1. A user orders a product and is redirected to the payment processor.
  2. While the user is paying, another user orders the product and it's now out of stock.
  3. The user completes payment, but the order can't be created because the product is out of stock.

This can be avoided by reserving the product before attempting payment. But there's some complexity in doing so - if the payment fails, products need to be un-reserved, and a timeout is needed in case the user never completes the payment process.

So my question: is it worth implementing the reserve process? Or is this scenario rare enough to just not worry about it and resolve things manually if it does happen?

The answers probably depends on exactly what's being sold. However, I don't know this - I'm developing generic software to be used by all sorts of vendors. I could make it configurable, but still need a sensible default.

12
  • 19
    The answers probably depends on exactly what's being sold It depends entirely on what is being sold and how the business handles orders when inventory is low. It's not a problem if you sell silkscreened shirts and can make them on-demand, but it's a huge problem if you sell electronics produced in China and the manufacturer requires a two-month lead time.
    – Dan Wilson
    Commented Jul 9, 2020 at 11:24
  • 1
    Could one of the three downvoters provide some feedback please? I've tried to make the question as clear as I can, so it would really help to know why you downvoted, and if I could improve the question.
    – paj28
    Commented Jul 9, 2020 at 12:12
  • 3
    Not a down-voter, but I would just look at how other e-commerce platforms handle this. Shopify does an inventory check right before the customer goes to pay and holds it during payment processing. Seems like a sensible default. community.shopify.com/c/Shopify-Discussion/….
    – Dan Wilson
    Commented Jul 9, 2020 at 12:16
  • @DanWilson - Yeah, that's a good idea. I did try to do this, but I found it difficult to get a clear answer in documentation (e.g. for Magento). I was hoping people would include information like that in answers. So your link to info about Shopify is really appreciated!
    – paj28
    Commented Jul 9, 2020 at 12:18
  • 1
    About the downvotes: my first inclination based on the title was to cast a close vote (doesn't sound like a software problem) but after reading the question I changed my mind. Some people may not have taken the trouble. It may help if you change the title to something like "Race condition in ordering system". Commented Jul 18, 2020 at 7:10

5 Answers 5

34

You have two excellent answers (I've upvoted both). But they each address only a part of the problem, and this is why I feel obliged to come with a third answer

Your challenge is hybrid:

  • It's a business problem, exactly as Rik D pointed out: ultimately, the business is responsible for deciding how to deal with customers.
  • It's a user experience problem, exactly as 1201ProgramAlarm pointed out: and good IT products should promote good user experience.
  • But it's also an IT capability problem: if you want to reserve real-time, your online ordering system must be seamlessly connected to a back-end stock management system (1201ProgramAlarm clearly made that point). Personally, I know a lot of small businesses that still struggle with such an endeavour (inaccuracy mentioned by Rik is only one of the potential symptoms in that regard).

It is a hybrid problem because it cannot be solved by just looking at one side of the medal. Business cannot come out with a good requirement if they don't know what's possible. Business experience in a shop is very different from the online experience in the browser, so some digitally native insights are also needed here. Both business and IT considerations have to be analysed together. Of course, ultimately, business people should have the final world, but after this dialogue.

In your special case, you do not have business people. Whatever choice you will make might, you'll lose: If you can't reserve, some will prefer a platform that can; If you oblige to reserve, small businesses will prefer less constraining solution.

So, in conclusion, if you can:

  • offer both approaches as a configuration option (to enlarge your market)
  • propose reservation by default (because that's what market leaders do, and your customer all dream of being one day a market leader ;-) )
2
  • 1
    Nice answer, thank-you. I agree there's definitely a business decision to either have really solid stock control (or responsive back-ordering) - or to have the occasional poor customer experience. So I'll definitely have an option like "allow order when out-of-stock". For merchants that do not allow out-of-stock orders, I think they'll always want reservation, so I'll just enable this, no need to provide a config option. Very useful feedback, thank-you!
    – paj28
    Commented Jul 9, 2020 at 12:30
  • 2
    "Business cannot come out with a good requirement if they don't know what's possible.", bravo. Commented Jul 29, 2020 at 10:50
18

This isn’t a software problem, it’s a business problem.

You should ask the business how they want to handle the situation. Perhaps they simply want to take the order and ship it a little bit late. For generic software, offering an option for the store owner to ignore empty stock and take the order is valid.

It’s not up to us, software developers, to decide how the business should work.

Another thing that comes to mind is that stock is often inaccurate. Even with a reservation system in place such as 1201ProgramAlarm described, it’s possible that a product is actually not in stock even if the system thinks it is. In this case your software might need a feature for customer service to reach out to the customer and offer them their money back or offer a replacement product, or some other option to make the customer satisfied. This could be much more valuable for the business then a reservation system for items in a shopping cart.

7
  • Two mentioned to two issue here. 1) Yes, there is a feature to allow out-of-stock orders, and I agree this is a busiess decision. 2) Also a feature for a seller to cancel an order and issue refund. Still, it's not a good user experience, so we want to do everything possible to avoid it. I'm not sure reserving during payment is a business decision, I think many business would see this as something the software should just handle, and would leave it in default config.
    – paj28
    Commented Jul 9, 2020 at 8:55
  • The other answer basically says "software must do this or it's useless". As you've posted a different opinion, perhaps you could comment on the other answer to explain why you disagree - it could open up an interesting discussion.
    – paj28
    Commented Jul 9, 2020 at 9:02
  • In fact it is an hybrid problem: it should indeed be driven by business, because business is responsible to handle the customers. But what the business can do depends heavily on what IT can propose. So it should be a dialogue and not a simple requirement gathering.
    – Christophe
    Commented Jul 9, 2020 at 9:16
  • @Christophe - This is low-cost self-admin e-commerce software. I'm not talking about a bespoke development where developers would have a dialogue with the business. I could make it a config option, which would have the same effect as a dialogue. But I think most users will not look at an option like this and just use the default.
    – paj28
    Commented Jul 9, 2020 at 9:21
  • 3
    @paj28: Some answers are written not because the answerer disagrees with the other answer but because there are viable alternatives or interpretations that haven't yet been mentioned. Pitting answerers against each other is not productive. People can comment on answers if and when they want to and shouldn't be required to do so just to compete with other answerers.
    – Flater
    Commented Jul 9, 2020 at 11:09
14

Look at it from the user's side: would you like to order a product, go thru all the payment details page (including, for example, entering credit card data), having your card charged, then having the system come up and say, "Oops, we seem to have run out of those"? Then you'd have to refund or undo the transaction, which may incur fees for the retailer.

It is much better to put a hold on a product (reserve it) when it is ordered. This is like putting the product into your shopping cart in a brick and mortar store. In either case, if the cart is abandoned it will eventually be put back on the shelf.

If the order sits in the cart long enough, it would need to be refreshed. At that time you may notice that it is out of stock, and the user can be notified.

The additional complexity of the reservation system will make for a much better experience for your shoppers.

7
  • Sure, makes sense. Just to be clear: is this something that most e-commerce software (Magento, etc.) implements?
    – paj28
    Commented Jul 8, 2020 at 22:27
  • 5
    @paj28: As a customer, I would be absolutely pissed off if you can't deliver after I entered my payment details, and I would think that I have been scammed. You would have lost a customer forever. If some e-commerce software doesn't implement this, you shouldn't ever consider using it.
    – gnasher729
    Commented Jul 8, 2020 at 22:34
  • @gnasher729 - Totally agree from customer PoV. Ok, so this functionality is standard. Any idea what a typical timeout is when the user doesn't complete the payment process? I'd guess 10 minutes or so?
    – paj28
    Commented Jul 8, 2020 at 22:49
  • A timeout of 10 minutes for the payment process is quite reasonable. But what to do with the shopping cart? Best is to leave it intact for a long time, because it is normal that the item will still be available say in a month, and check the items before the user tries again to check out. Emptying the shopping cart will mean lost sales.
    – gnasher729
    Commented Jul 8, 2020 at 23:04
  • Good idea about keeping the shopping cart. Could even notify user when stock available again. Any concerns about denial-of-service attacks? A malicious competitor could create a bunch of accounts, and with each one begin the checkout process - reserving all stock of the product and preventing new orders.
    – paj28
    Commented Jul 8, 2020 at 23:22
11

With so many good answers it seems strange to say that you and they have missed something. But I think you have, and I think that it may help you.

Payment processors do not just let you charge credit cards. In fact I am not at all sure that they let you charge cards at all. What they actually do is this:

  1. Obtain authorisation from the card issuer for a charge of the amount specified. This may or may not succeed.
  2. Charge the card according to the authorisation. This will only fail in really exceptional circumstances.

There is no reason not to do 1 before reserving the goods. It costs the cardholder nothing.

As for 2, you have three choices:

  • Charge automatically at the time of authorisation. This is the simplest but it does mean that you need to be ready to refund, and refund fast, if for any reason the goods cannot be sent.
  • Charge automatically at some later time. This is not appropriate for you, but it is the best choice of sellers of revocable digital goods. I do it. The card is charged 72 hours after purchase. Thus if anything goes wrong (wrong purchase, fraud, etc) I can prevent the charge before it happens, as long as the problem reveals itself fast.
  • Charge manually still some later time. This is best for physical goods. Having reserved the goods at the time of authorisation, you make the actual charge immediately before sending the goods.

Not to make any specific recommendations- but the broader landscape may offer you (and other readers) some better choices.

1
  • I may be mistaken but my understanding is the best practice (which may be required by some legislation) is that you shouldn't charge until you've shipped. Therefore the correct approach may be to authorize payment, process the order, and then charge payment. Commented Jul 30, 2020 at 17:15
1

If you are selling a time sensitive product, sold on first come first serve basis, reserving the product doesn't makes any sense, a valid example is a ticket to a concert or an airline ticket, in such cases you are often connected to the ticket distribution systems in real time.

For cases where time is not of much relevance the product could be reserved and later made available if the payment fails or the user doesn't complete it, a valid example is of selling TVs online, maybe. In case you do not want to reserve the product then it would become more complex and you might end up making calls to the dependent system several times.

Yes, the UX is important but you also need to keep in mind that if you don't hold the inventory database or if multiple other online vendors are selling the same items you are actually racing against them as well.

4
  • 2
    I'm a bit confused about this answer. You say reserving a concert ticket doesn't make sense. What makes you say that? You can reserve it like any other product. When selling with multiple online vendors, there is a system (like Linnworks) to sync inventory. If a reservation is made, inventory decreases by one on all channels.
    – paj28
    Commented Jul 10, 2020 at 13:44
  • 1
    If the preference is for first come first serve, then the whole transaction including the order procurement and payments should be considered a single unit of work, though one may make calls to check for the inventory of that product at different steps. but again it all depends on the business use case Commented Jul 10, 2020 at 14:10
  • Yes, single unit of work would be ideal. Is that possible with most payment processors? They'd need an API that supported some kind of two-phase commit. Also, you say this depends on the business use case, but what exactly depends? Can you give an example of two businesses that would prefer different processes?
    – paj28
    Commented Jul 10, 2020 at 21:04
  • 1. Whether to reserve the product is a business decision, it depends on the use case; 2. If there's a mechanism like a wallet which is internal to the system such that no external financial institution is involved in the payment processing the complete process could be smoother 3. Can't understand what exactly you mean by businesses that follow different process, which process? Commented Jul 11, 2020 at 17:07

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