-2

I have a problem with my e-commerce site.

There can be multiple simultaneous requests to add items in the shopping cart,

I was moving towards the design where when an item is added to the shopping cart the stock count would be reduced in the database.

However When the system was under load the item row would be locked and this would mean that other threads would have to wait. This would create lot of backlogged update requests, which may start timing out eventually.

Please help me out to understand how such situation can be handled.

3

The problem is of course the database access on the 'add to basket' request.

Customers will add stuff to their basket all the time, they aren't always going to be buying that item. Plus at times of high load, say in a sale, even large ecommerce sites simply don't have the processing power to have 'add to basket' requests processed on the server side.

If you want a scalable e-commerce site, you need to push all the processing you can to the client. 'Add to basket' should be a purely client side operation and not update the stock level.

You can check the stock levels during the purchase process if you like, which will require server side processing in anycase. But I believe the current best practice in e-commerce is not to check stock levels until you actually try and fulfill the order in the warehouse.

If the order can't proceed at this point then you can email the customer and tell them their order is delayed while new stock is delivered or cancelled.

This maximises your income, as customers are usually happy to wait a bit longer rather than cancelling the order, but if they see 'out of stock' on the website, they will not place that order.

Furthermore you can assess the demand for the item in question and order more from your supplier if required.

  • It seems a strange practice not to check the stock at all until after the customer places the order. That just wastes the customer's time if they try to place an order for something you don't have. Sites such as Amazon tell you when you view the item how many they have (at that moment). – Simon B Aug 30 '18 at 13:52
  • No they dont. It looks like they do, but in fact it's just a cached estimate. for example. amazon.com/gp/help/customer/display.html?nodeId=201910280 – Ewan Aug 30 '18 at 13:59

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