I am facing issue trying to design it correctly.Problem is simple- there is 1-click button to buy one type of coupon. It is single row entry in DB with 1000 as stock count. Assume QPS as 1 million and only 1k coupons. If I go with pessimistic lock, I have to give timeout to each user. It is not looking something scalable.If I go with optimistic lock, with VERSION column in table to verify while update, how do I refresh versions of users? For eg., if 10000 users come at time=0, and only one guy gets it, the rest of users need to keep obtaining a new lock. What is the best way to design this?
Designing high concurrency sale
design;database design;concurrency;scalability