If the Library Management System must support reserving books that are currently loaned out, which design change best handles the edge case where multiple users reserve the same book simultaneously?
hard🎤 Interviewer Follow-up Q15 of Q15
OOP & Design Patterns - Design a Library Management System - LLD with Relationships & Edge Cases
If the Library Management System must support reserving books that are currently loaned out, which design change best handles the edge case where multiple users reserve the same book simultaneously?
ALet the User class maintain their own reservation list independently without central coordination.
BAllow multiple reservations by updating the book's status to 'reserved' without tracking order.
CAdd a reservation queue in the LoanManager and process reservations in FIFO order with atomic updates.
DImplement a polling mechanism where users repeatedly check book availability without reservations.
Step-by-Step Solution
Step 1: Why a reservation queue?
FIFO queue ensures fairness and order in handling multiple reservations.
Step 2: Why not multiple reservations without order?
Allow multiple reservations by updating the book's status to 'reserved' without tracking order. causes ambiguity and race conditions in fulfilling reservations.
Step 3: Why not user-maintained reservations?
Let the User class maintain their own reservation list independently without central coordination. lacks centralized control, risking inconsistent reservation states.
Step 4: Why not polling without reservations?
Implement a polling mechanism where users repeatedly check book availability without reservations. leads to poor user experience and race conditions.
Final Answer:
Option C -> Option C
Quick Check:
Centralized, ordered reservation management with atomic updates handles concurrency and fairness.
Quick Trick:Use a centralized FIFO reservation queue to handle concurrent reservations fairly [OK]
Common Mistakes:
MISTAKES
Ignoring reservation order and fairness
Decentralizing reservation tracking
Relying on user polling instead of system-managed reservations
Trap Explanation:
PITFALL
Options B, A, and D seem simpler but fail to handle concurrency and fairness properly.
Interviewer Note:
CONTEXT
Tests advanced understanding of concurrency, edge cases, and system design extensions.
Master "Design a Library Management System - LLD with Relationships & Edge Cases" in OOP & Design Patterns
2 interactive learning modes - each teaches the same concept differently