Quick revision
The short answer
The key insight is to separate Book, the title, from Copy, the physical item: loans reference a Copy, because a member takes home one specific item, and reservations reference a Book, because the member wants any copy of the title. Book and Author are many-to-many through a book_author table with (book_id, author_id) as its key, Member and Copy each have many loans over time but a copy has at most one open loan, enforced with a partial unique index, and a reservation has member, book, created_at and status with a rule against duplicate active reservations.
What to remember
In this answer, we separated Book, the title, from Copy, the physical item, so loans reference copies and reservations reference books. We modelled Book to Author as many-to-many through book_author, enforced at most one open loan per copy with a partial unique index while keeping full loan history, prevented duplicate active reservations the same way, and noted that cardinalities come from business rules we should state and confirm.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The key insight is to separate Book, the title, from Copy, the physical item: loans reference a Copy, because a member takes home one specific item, and reservations reference a Book, because the member wants any copy of the title. Book and Author are many-to-many through a book_author table with (book_id, author_id) as its key, Member and Copy each have many loans over time but a copy has at most one open loan, enforced with a partial unique index, and a reservation has member, book, created_at and status with a rule against duplicate active reservations.
Why this question is asked
A library is a small domain, but it contains most of the decisions real models need: the difference between a thing and an instance of it, many-to-many relationships, relationships that change over time, and rules that are true only for current rows. Interviewers use it because there is no trick, only clear reasoning about business rules. In this answer, we will separate titles from copies, model authors, loans and reservations, write the tables with the constraints that enforce the rules, and finish with the assumptions we would confirm, plus fines and condition history.
1The Key Insight: Book Versus Copy
The word book means two different things in a library. When a member says I want to borrow Dune, they mean the title. When the desk scans a barcode, it means one physical item, one of four copies of Dune. If we model both as one book table, we cannot say which copy is out, how many copies are available, or which damaged copy needs replacing.
So we have two entities. Book is the title, with ISBN, title and publication year. Copy is a physical item, with its own barcode and a reference to its book. That one split decides the rest: a loan is about a specific copy, because a specific item leaves the building, while a reservation is about a book, because the member will take whichever copy comes back first.
2Entities, Relationships and Cardinalities
With that split, the relationships fall into place. Each statement of cardinality comes from a business rule, so we write the rule next to it.
| Relationship | Cardinality | Business rule behind it |
|---|---|---|
| Book - Copy | 1 : N | a title has many physical copies; a copy is of one title |
| Book - Author | M : N | co-authored books; authors write many books |
| Member - Loan | 1 : N | a member borrows many times |
| Copy - Loan | 1 : N over time | at most one open loan per copy at a time |
| Member - Reservation | 1 : N | a member can reserve several titles |
| Book - Reservation | 1 : N | a reservation is for a title, not a copy |
Notice the difference between a relationship over time and at a moment. Over its life a copy has many loans, so Copy to Loan is one-to-many. At any moment it has at most one open loan. Both statements are true, and the schema must express both: the one-to-many shape through the foreign key, the at-most-one-open rule through a constraint.
3The Tables
Here are the tables in PostgreSQL. Book to Author needs a join table, because a foreign key column can only point to one row. Its primary key is the pair, so the same author cannot be attached twice, and a position column keeps the author order shown on the cover.
The partial unique index is the important line. It indexes only rows where returned_at is NULL, the open loans, and requires copy_id to be unique among them. Closed loans are not in the index, so history can hold any number of loans per copy, while a second open loan for the same copy fails, even when two desk clerks scan the same barcode at the same moment.
4Reservations and the Duplicate Rule
A reservation records who wants which title and when they asked, which gives the queue order, plus a status that moves from waiting to ready to collected, cancelled or expired. The rule is that a member should not hold two active reservations for the same book.
The same partial index technique applies. MySQL has no partial indexes, so there we would use a separate current_loan table with copy_id as its primary key, or a generated column that is non-NULL only for open rows with a unique index on it. When a copy is returned and someone has a waiting reservation for that book, the application marks the oldest one ready and may hold the copy for them.
5Assumptions to Confirm
Every cardinality above is a business rule, and rules differ between libraries. Can a member reserve a specific edition rather than a title? Is there a limit of, say, five open loans per member? Can a reference copy never be loaned? Are e-books, which have no physical copy but a licence count, in scope? In an interview, and on a real project, we state the rules we assumed and ask about them instead of guessing silently, because a wrong cardinality is much more expensive to fix after data exists.
6Follow-up questions
How would you record fines for late returns?
As their own table, fine(id, loan_id, member_id, amount, reason, created_at, paid_at, waived_at), with one fine per late loan or several for damage. A fine belongs to a loan because the loan has the due date and return date that justify it, and it keeps the member id for quick balance queries. Amounts should be stored as numeric in the library's currency and never recalculated from a rule later, since rules change; payments can be a separate table if partial payments are allowed.
Where would you put a copy's condition history?
In a copy_condition table with copy_id, condition, noted_at and noted_by, adding a row whenever staff assess a copy, typically at return. The copy row can keep the current condition for convenience, but the history table answers who reported the damage and when, which matters when fines for damage are disputed.
Why not store authors as a text column on book?
Then we cannot list all books of an author reliably, names get spelled differently, and we cannot store author details once. The join table makes the many-to-many relationship queryable and keeps each author in one row.
7Conclusion
In this answer, we separated Book, the title, from Copy, the physical item, so loans reference copies and reservations reference books. We modelled Book to Author as many-to-many through book_author, enforced at most one open loan per copy with a partial unique index while keeping full loan history, prevented duplicate active reservations the same way, and noted that cardinalities come from business rules we should state and confirm.
Open with
The most important decision is separating Book, meaning the title with its ISBN, from Copy, the physical item with a barcode. A loan references a copy, because a specific item leaves the building, and a reservation references a book, because the member wants whichever copy comes back first.
Then, if they want more
Book to Author is many-to-many, so I would have a book_author join table with book_id and author_id as the primary key and a position column for author order. Member to Loan is one-to-many, and Copy to Loan is one-to-many over time, but a copy has at most one open loan at a time.
I would enforce that in PostgreSQL with a partial unique index on loan copy_id where returned_at is null, which keeps unlimited history but rejects a second open loan, even under concurrency; in MySQL I would use a current_loan table keyed by copy_id.
A reservation has member_id, book_id, created_at for the queue order and a status, with a partial unique index on member and book for active statuses so nobody holds two active reservations for the same title. Fines would be a separate table tied to the loan, and condition history a table of assessments per copy.
Finally, I would say that these cardinalities are business rules, list the ones I assumed, such as loan limits or reserving editions, and confirm them rather than guess.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Model a small library system: members borrow copies of books, a book has many authors...": https://scrivio-interview-library.netlify.app/databases/data-modeling/fea2e8cae4/