I'm currently working on a project that involves a booking system. However, I've encountered an issue related to oversold bookings. Specifically, when two users attempt to book the same tickets simultaneously, the system sometimes ends up selling more tickets than available (e.g., selling 6 tickets when there are only 5).
To address this issue, I initially implemented a temporary booking system where a ticket is reserved for 10 minutes. However, I've noticed that if different users attempt to book the same tickets with very close timing, the problem persists.
What I have tried:
After conducting extensive research, I've come across a potential solution: implementing a queue system for bookings. The idea is to add bookings to a queue and then process them one by one by calling the booking API.
I'm currently working with NestJS and a MongoDB database, and I'm seeking guidance on how to implement this flow. If anyone has experience with this or has alternative solutions to address oversold bookings in a booking system, I would greatly appreciate your insights