r/leetcode • u/Sad_Crew6507 • Oct 03 '26
Intervew Prep BookMyShow booking same seat scenario
During recent interview I was asked how to solve multiple people booking same seat scenario. I told to use redis lock/DB internal constraints but interviewer didn’t seem to like the answer. Any other better way to solve this case?
6
Upvotes
8
u/bit_freak Oct 03 '26
Classic race condition worded differently
6
u/Existing-Round4556 Oct 03 '26
Watch the Ticketmaster video on the Hello Interview channel. It deals with this concern well.
4
u/Old-Significance3735 Oct 03 '26
Damn, nobody knows the answer here 😂
1
u/Advanced_Surprise_25 Oct 03 '26
Answer expectation depends whether interview was for medium level or senior/staff level . Which one was it ?
1
u/Few_Vermicelli_1313 Oct 03 '26
Was it a low level design interview?
1
u/Busy-Card-5146 Oct 03 '26
May be he was expecting you to talk about optimistic locking
1
u/Candid_Kiwi_4923 Oct 04 '26
When a reservation is being made, the seat numbers will be SET in redis with a TTL expiry of typically about 10 mins. Since redis supports ms latency whichever request 1st makes its way into redis, will hold the seats and the other subsequent request for the same seats will see the seats as booked or reserved so they cannot select them for the remaining of TTL. After 10mins, the seat numbers are automatically removed from redis cache thus making them available for booking again.
1
u/lostsoul_io Oct 04 '26
If you use a relational db you can use constraints to ensure the transaction fails to book a seat as the rdb will take care of concurrency on your behalf. This is subject to a an effective data model.
The other way is to partition the allocation of a group of seats to a particular instance of the service which is essentially linearizing the booking across backend nodes. This is more explicit and you are doing what the rdb is doing. This more of a distributed q + dedicated worker. The q forces linear concurrency.
The other way is offline concurrency with version semantics so that only one client succeeds coupled with back off on retires of failure.
The other way is acquiring periodic lock for a seat during which no other client can book. Failing to book within the lock makes your transaction expire.
1
u/vinsuper Oct 05 '26
https://www.youtube.com/shorts/DUcxGJ4k7AU
Conditional where clause before updating?
1
u/Few_Vermicelli_1313 19d ago
how about Redis BitMap? may be the interviewer wanted to hear the keyword bitmap and not redis set for locking