I am building a website using Next.js, React, and MongoDB Atlas. I want to implement a raffle system where a user can select and purchase a number. Once the payment is completed, the number is assigned to the user. However, I am unsure how to handle the scenario where two users click on the same number at the exact same moment, causing a conflict.
How can I ensure that only one user can purchase a specific number even if multiple users attempt to select it simultaneously? What are the best practices for handling this kind of concurrency issue with MongoDB?