Design a Library Management System
📚 What is a library management system? It is the software at the front desk of a library. It knows which books the library owns and how many copies of each, who has borrowed which copy and when it is due, and who is waiting for a book that is all lent out. When a copy comes back late, it charges a fine, and a member with an unpaid fine cannot borrow until they pay.
The library is a favourite medium-level problem because it looks like a CRUD app and is not. The interesting part is a single copy that can be in several places: on the shelf, in a member's bag, or set aside for someone who placed a hold. Most bugs in candidate solutions come from losing track of where a copy is, or from letting the wrong member take a copy that was promised to someone else.
Requirements
"Design a library system. Members borrow books and return them. Late returns are fined, and members can put a hold on a book that is checked out."
The prompt is short, and each sentence hides a decision. The questions below are the ones that change the classes or the tests.
Clarifying Questions
You: Does the library own one copy of each book, or several?
Interviewer: Several. A popular book can have five copies on the shelf. Members borrow a copy, not "the book".
You: How many books can one member have at a time, and for how long?
Interviewer: Up to 3 copies at once. Each loan is due 14 days after checkout.
You: How do fines work?
Interviewer: 1 per day late. The fine goes on the member's account, and a member who owes anything cannot borrow until they pay it off. The fine rules change from time to time, so keep them easy to swap.
You: When a book with holds is returned, can anyone pick it up?
Interviewer: No. Holds are first come, first served. The returned copy is kept for the first member in the queue, and nobody else can take it.
You: When can a member place a hold?
Interviewer: Only when no copy is on the shelf. If one is there, they should just borrow it. And only one hold per member per book.
You: Should the system read the clock to compute due dates?
Interviewer: Pass the day in with each call, as a number. It keeps the tests simple.
You: Do we need search by title or author, or a catalogue with authors and genres?
Interviewer: Not now. Identify a book by its ISBN.
The fourth answer is the one that shapes the design. "A returned copy goes to the next hold" means a copy can be free but not available. Our model needs a place for that state, and every path that frees a copy must respect it.
💡 Interview tip: Ask what a hold actually reserves. "The member gets a notification" and "the copy is set aside for them" are very different designs. The second one changes what "available" means, and the interviewer will test exactly that.
Final Requirements
- The library owns books, identified by ISBN, and one or more physical copies of each. New copies can be added at any time.
- A registered member can check out an available copy of a book. Each loan is due 14 days after checkout.
- A member can have at most 3 copies on loan, and a member with an unpaid fine cannot check anything out.
- When a copy is returned late, the member is fined 1 per day after the due day. Fine rules change, so swapping them must not touch the rest of the system.
- When no copy of a book is on the shelf, a member can place a hold on it, at most one per book. Holds are served in the order they were placed.
- When a copy becomes free (a return, or a newly added copy) and someone is waiting, the copy is kept for the first member in the queue. Only that member can borrow it.
- Members can pay toward their fines. Anyone can ask how many copies of a book are on the shelf.
Out of scope
- Search, catalogue details (authors, genres, editions) and recommendations.
- Renewals, pickup deadlines for holds and lost or damaged copies (we come back to some of these in Extensibility).
- Payment processing: we only record what is owed and paid.
- Several front desks at the same time (also in Extensibility).