My client has an e-commerce site that sells electronics, and there were situations when the product was sold many times more than they had in the inventory. This is because if two users buy a product at a time when there is only one product left in the warehouse, one session does not complete the registration of the product as sold before the start of another session (therefore, it continues as usual, thinking that there is one on the left), although There is a check at the beginning of the process. This, obviously, will cost money (fee for return, refund, etc.) And inconvenience to consumers.
So I was wondering if I could fix it anyway? I was thinking about creating a “marker” at the beginning of the process, that is, it will check the inventory and, if it is sold, it will mark the product as such, thereby preventing other sessions from buying it. But this also creates an additional problem: if something happens on the client’s side, which will lead to their cancellation of the average process (loss of power, etc.), then even if the product is marked as sold, it is not actually sold from the moment of placing the order the process is not over. If this continues, there will be an excess of products. Secondly, it is also possible that the session will check for WHILE inventory when another session marks it as sold, so the first session will continue, although the second session has already bought it. This brings us back to the original problem.
I look at table locks at the end of the database, but I'm not sure if this is the best idea. Any suggestions would be much appreciated!
Thanks dyip
source share