Bird
Raised Fist0

Consider a scenario where two users simultaneously attempt to borrow the last available copy of a book. What is the expected behavior of the system to maintain consistency?

medium🧠🧾 Concept Trace Q4 of Q15
OOP & Design Patterns - Design a Library Management System - LLD with Relationships & Edge Cases
Consider a scenario where two users simultaneously attempt to borrow the last available copy of a book. What is the expected behavior of the system to maintain consistency?
AThe system uses locking or transactions to ensure only one loan succeeds, the other is notified of unavailability
BThe system duplicates the book copy to satisfy both requests
CThe system queues both requests and grants loans in order without concurrency control
DBoth users are allowed to borrow the book, and the system resolves conflicts later
Step-by-Step Solution
Solution:
  1. Step 1: Identify concurrency risks with simultaneous loan requests

    Simultaneous requests can cause race conditions leading to inconsistent state.
  2. Step 2: Apply concurrency control mechanisms

    Using locks or transactions ensures atomicity so only one loan is granted.
  3. Step 3: Notify the unsuccessful user

    The other user is informed the book is unavailable and can be offered reservation.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Concurrency control prevents double-loaning [OK]
Quick Trick: Concurrency -> locking or transactions needed [OK]
Common Mistakes:
MISTAKES
  • Allowing both loans and fixing later
  • Ignoring concurrency control
  • Duplicating physical copies unrealistically
Trap Explanation:
PITFALL
  • Candidates often underestimate concurrency issues and pick naive solutions.
Interviewer Note:
CONTEXT
  • Assesses knowledge of concurrency and data consistency in system design.
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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes