S
S
Sergo Sergo2016-04-14 14:35:11
MySQL
Sergo Sergo, 2016-04-14 14:35:11

How to compensate for the delay?

there is a store on the site, it has goods. Due to the high traffic of the site, goods in the store are bought up very quickly and it happens that 2 people buy one product at the same time. There is a check to see if the product was purchased or not, but due to the micro-delay in updating the database, it turns out that the product is bought from two people. How to be?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaliy Kravchishin, 2016-04-14
@freevital

Read: transactions and locks

M
Maxim Timofeev, 2016-04-14
@webinar

When adding to the cart, it is necessary not only to check for availability, but also to write off (or reserve), then return it if a purchase has not been made

N
Niomin, 2016-04-14
@Niomin

At the time of purchase of the goods, use a transaction and a request of the form select for update
Detailed in the documentation

I
Ilya Voropaev, 2016-05-07
@SV0L0Ch

It can be configured so that the product with less than N pieces left is not available for purchase or is marked something like "remains in stock - unknown". In this case, when approaching the minimum, the user simply will not be able to add the product to the cart instead of a bummer when placing an order, or at least be ready for this bummer, realizing that the product may no longer be available.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question