Menu

What happens when two people buy the last item?
📰

What happens when two people buy the last item?

DEV Community: backend·Emmaculate Jane Akinyi Odhiambo·about 13 hours ago
#LXilJwVw
#devtobackend#devto#dev#ticket#happening
Reading 0:00
15s threshold

Emmaculate Jane Akinyi Odhiambo

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.