Bird
0
0

Given this simplified booking code:

medium📝 Analysis Q4 of 15
LLD - Design — Hotel Booking System
Given this simplified booking code:
def book_slot(slot_id):
    if is_available(slot_id):
        reserve(slot_id)
        return 'Booked'
    else:
        return 'Unavailable'

What happens if two users call book_slot for the same slot at the same time?
ABoth users get 'Unavailable' always
BBoth users get 'Booked' because reserve is atomic
COne user gets 'Booked', the other gets 'Unavailable' if reserve locks properly
DThe system crashes due to race condition
Step-by-Step Solution
Solution:
  1. Step 1: Understand race condition in concurrent booking

    Two users checking availability simultaneously can cause conflicts.
  2. Step 2: Analyze reserve locking effect

    If reserve locks the slot properly, first user books, second sees unavailable.
  3. Final Answer:

    One user gets 'Booked', the other gets 'Unavailable' if reserve locks properly -> Option C
  4. Quick Check:

    Proper locking = one booked, one unavailable [OK]
Quick Trick: Locking ensures only one booking succeeds [OK]
Common Mistakes:
  • Assuming both can book simultaneously
  • Thinking system crashes on race
  • Believing reserve is always atomic without locks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes