Bird
Raised Fist0

Consider this simplified booking flow code snippet:

medium📝 Analysis Q13 of Q15
LLD - Design — Hotel Booking System
Consider this simplified booking flow code snippet:
def book_slot(slot_id):
    if is_available(slot_id):
        reserve(slot_id)
        confirm_booking(slot_id)
        return 'Booked'
    else:
        return 'Unavailable'

What issue can arise if two users call book_slot at the same time for the same slot_id?
ABoth users might get 'Booked' causing double booking
BThe system crashes due to race condition
CBoth users get 'Unavailable' response
DOnly one user can call the function at a time automatically
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the code flow for concurrency

    Both users check availability before reservation without locking, so both may see the slot as available.
  2. Step 2: Understand race condition effect

    Without locking, both reserve and confirm booking, causing double booking.
  3. Final Answer:

    Both users might get 'Booked' causing double booking -> Option A
  4. Quick Check:

    Race condition = double booking risk [OK]
Quick Trick: Check-then-act without lock causes double booking [OK]
Common Mistakes:
MISTAKES
  • Assuming system crashes automatically
  • Thinking both get 'Unavailable' response
  • Believing function serializes calls automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes