Design a library management system 00:00:00 Make a prediction You will trace one checkout through member eligibility, copy availability and a loan that identifies the actual barcode. A member has one borrowing slot left. Two clerks lend two different copies simultaneously. Is a lock on each copy sufficient to enforce the member's limit? No. The two copy locks protect different objects. The check and increment of that member's active loans also need a shared consistency boundary. 00:00:31 The toy van, one card per toy A toy library has two identical blue boats on different numbered cards. A loan moves one card to a child; the other boat remains on the shelf. A waiting basket holds a returned boat for the first child in line. Distinguish title, physical item, loan and hold. A single availability flag on the title loses facts that the desk must know when a specific barcode returns. A library management system in a low-level design round is the software behind the counter: what the library owns, who may borrow, who has what until when, who waits for it, and what a late day costs. It is asked because everybody knows libraries, and because the word book hides a modelling question that experience answers at once: is it the text or the thing in your hand? 00:01:23 Lend the right physical copy Two physical copies share the same title. One is already borrowed and copy B2 is available. A member asks to borrow B2. Check both member eligibility and copy availability inside the relevant transaction. Create a loan identifying B2 and its due date, then mark exactly that copy unavailable. Return B2 using the loan identifier. The other copy's borrower remains unaffected. This is why title, physical copy and loan have distinct identities. Lend copy A and leave copy B available under the same title. Scan B at the desk as a return: that action cannot automatically close A's loan. Storing status solely on the title loses enough identity that both lending B and returning the wrong item become ambiguous. 00:02:14 Two desks, one borrowing limit A member has one loan slot left. Two clerks check out different copies for the same member at once. Locking only each copy protects stock but not the member limit. Include the member's eligibility in the same consistency boundary and test the competing checkouts. A member has one remaining borrowing slot. Each desk locks a different physical copy, sees the same member allowance, and grants a loan. Both copies are individually consistent while the member exceeds the limit. Guard the member rule as well as the availability of each copy. Protecting every copy perfectly still permits a member to exceed their allowance when eligibility is updated independently. If holds are made at title level, allocate a particular returned copy to the next eligible hold explicitly; keep that different from an already issued loan. BIBFRAME: work, instance, item. The Library of Congress model has three levels. An item is an actual copy, with its location, shelf mark and barcode. Instance and item are our title and copy. Open Library: works and editions. Its public API has works and editions as separate resources. A step above our title: several editions of one work. 00:03:37 Try an interview follow-up You have a lock in each book. Two counters serve the same member. What can go wrong? The member’s borrowing limit can still break. Imagine four active loans with a limit of five. Two desks lock different copies, both read four and both lend successfully, leaving six. Guard the member's loan count together with the chosen copy, in one transaction or through an agreed lock order. A library owns two physical copies of the same title. One is on loan and one is returned damaged. Can a waiting member collect a copy? Track identity and condition per copy, and express the waiting request at the title level. Offer the member a particular lendable copy only when one exists. 00:04:26 What to take with you A title is a description and a copy is a thing. Members borrow copies and wait for titles. The loan is an object that knows the copy, the member, the plan and the due day. Kinds of members are plans with numbers; only the fine is a strategy. A copy that becomes free goes to the first who waits, under the same lock that closed the loan, and only then to the shelf. A kept copy lapses to the next person. Messages are written with the change and sent after it.