DEV Community

What happens when two people buy the last item?

So let's imagine there's only 1 ticket left, and 2 buyers click "Buy" at the same time—order successful. But this is not supposed to be happening because there's only 1 ticket, so there's no way both of them could have gotten a ticket if there's only 1 remaining. If you were building this website, how would you stop such from happening? Where exactly did things go wrong in our code? Because it was perfectly fine. The problem began when we first read the stock. So, as you can see, this is not a bug that can crash your system; it's a very tiny thing.

Top comments (0)