How do you handle the book reservation system in LLD?
Fast recall
Quick revision
Core answer
Can you model ordered waitlists and implement the Observer pattern to handle asynchronous notification when inventory becomes available
Freshers often use a simple list without FIFO ordering or forget to notify waiting members when a book returns, breaking the reservation flow
Mention expiration timers—if the notified member doesn't pick up the book within 24 hours, move to the next reservation in queue
Interview-ready guide
Interview answer
I'd treat reservations as a fairness problem: the member who reserved first should get the next copy. So each Book keeps a FIFO queue of reservations. When a member wants a title that's currently all checked out, I append a Reservation to that book's queue with a timestamp. The queue ordering is what guarantees first-come-first-served.
The interesting part is what happens on return. When any physical copy of that title comes back, the system needs to check the reservation queue and, if someone's waiting, hold the copy for them and notify them rather than just putting it back on the shelf. I'd wire this with the Observer pattern: the BookItem notifies its Book that its status changed, and the Book handles the logic — it polls the head of the queue, and if there's a member waiting, it marks the copy reserved and sends them a notification through a NotificationService. If the queue is empty, it just marks the copy available. The Observer indirection keeps the return logic decoupled from the notification mechanism, so I can swap email for SMS without touching the return flow.
A couple of refinements I'd mention: reservations should be at the title level, not a specific copy, because any returned copy satisfies the hold. And I'd add a hold window — the reserved copy is kept for the member for, say, 48 hours, after which it rolls to the next person, so a no-show doesn't block everyone behind them.
How do you handle the book reservation system in LLD
Direct Answer
Use a queue per Book to store Reservations in order. When a Member reserves, append to the queue. On BookItem return, the Book checks its reservation queue and notifies the first Member. Implement Observer pattern where BookItem notifies Book of status changes, and Book processes the next pending Reservation.
Deep Dive & Architecture
Reserve the title and fulfil with a copy
A member usually reserves a title when every copy is unavailable. The title keeps an ordered queue of active reservations. A reservation records the member, request time, status, and—after fulfilment—the copy assigned to it. Duplicate active reservations by the same member can be rejected.
A return creates a temporary hold
When a copy is returned, the service removes expired or invalid reservations, selects the next eligible member, marks the copy HELD, and sets a pickup deadline. It then sends a notification. If the deadline passes, the hold expires and the same copy is offered to the next member; if the queue is empty, the copy becomes AVAILABLE.
The claim must be atomic
Two returned copies or two service instances must not fulfil the same reservation. The storage operation should conditionally change one reservation from WAITING to READY and one copy from RETURNED to HELD in the same transaction. A queue describes ordering, but the transactional state change is what prevents double allocation.
Code Example
class Book {
private final Queue<Reservation> reservations = new LinkedList<>(); // FIFO = fairness
void reserve(Member m) { reservations.add(new Reservation(m, LocalDateTime.now())); }
// called when any copy of this title is returned (Observer callback)
void onCopyReturned(BookItem item) {
Reservation next = reservations.poll(); // head of queue
if (next != null) {
item.markReserved();
NotificationService.notify(next.member(), "Your reserved book is available");
} else {
item.markAvailable();
}
}
}
record Reservation(Member member, LocalDateTime at) {}
FIFO Queue guarantees first-come-first-served; the returned copy is held for the head member.
Common Mistakes & Pitfalls
- Using a Set or list without order — breaks first-come-first-served fairness; use a
Queue. - Coupling return logic to notifications — a returned book directly emailing users. Use Observer so the
Bookdecides. - No hold/expiry — the reserved copy should be held only for a window, then offered to the next member.
- Reserving at
BookItemlevel — reservations are per title (Book), satisfied by any copy.
Check your understanding
Answer these without looking back at the article.
- Design a library management system. What are the key classes?
- How do you model search functionality in the library system?
- How do you handle fines in the library management system?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.