System design interview: design a library management system

A library management system tracks a catalogue of titles, the physical copies of each, members, loans, returns and holds across one or more branches. The scale is small, so the interview is about modelling and correctness: separate a title from its copies, give each copy a clear state machine, serve holds in order from whichever branch a copy comes back to, and make checkout a single conditional update so one copy can never be lent twice.

By Published 8 min read

1. Clarify the requirements

This prompt can be asked as a class-design exercise or as a system for a city library network. Ask which, then cover both briefly. The rest of this page assumes a network of branches.

  • Functional: search the catalogue; see which branches have a copy on the shelf; borrow and return at any branch (staff desk or self-service kiosk); place, cancel and collect holds; renew a loan unless someone is waiting; overdue reminders; late fees if the library charges them; staff add and withdraw copies.
  • Non-functional: a copy is never on two loans; holds are served fairly in the order placed; checkout at the desk takes about a second; branches keep lending during a network outage.
  • Out of scope unless asked: e-books and digital lending (licences work differently), acquisitions and budgets, inter-library loans with other systems.

2. Estimate the scale

Numbers for a city library network (assumed figures)
QuantityAssumptionResult
Collection1 million titles, 3 million copies across 40 branchesabout 3 GB of catalogue and copy records at about 1 KB each
Members400,000 card holdersa small table
Circulation30,000 loans and 30,000 returns a dayunder 1 write a second on average; perhaps 10 a second at opening time
Catalogue searches200,000 a dayabout 2 a second on average, about 20 at peak
Loan history30,000 loans a day kept for a yearabout 11 million rows a year
Numbers for a city library network (assumed figures). Scroll sideways on a small screen.

Say it plainly: one relational database with a replica handles this comfortably. Distributing it would add risk without benefit. The interesting parts are the rules and the failure cases.

3. Define the API

GET  /v1/search?q=dune&format=book            -> titles with availability per branch
POST /v1/holds        { title_id, pickup_branch_id }
DELETE /v1/holds/{hold_id}
POST /v1/loans/renew  { loan_id }

POST /v1/circulation/checkout  { member_card, copy_barcode, branch_id }   (desk or kiosk)
POST /v1/circulation/checkin   { copy_barcode, branch_id }
  -> { next_action: "SHELVE" | "HOLD_SHELF" | "SEND_TO_BRANCH", branch_id }
Member and staff calls; kiosks use the same circulation calls as staff.

Check-in answers with what staff should do with the book in their hand. That one field is where the hold queue becomes a physical action.

4. Sketch the data model

Core tables
TableKey fieldsNotes
titlestitle_id, name, authors, ISBN, subjects, formatWhat people search for
copiescopy_id, barcode (unique), title_id, home_branch_id, current_branch_id, statusStatus drives circulation
membersmember_id, card_number, status, active_loan_countBlocked members cannot borrow
loansloan_id, copy_id, member_id, out_at, due_at, returned_at, renewalsAt most one open loan per copy (partial unique index where returned_at is null)
holdshold_id, title_id, member_id, pickup_branch_id, placed_at, status, copy_id, expires_atQueue order is placed_at; copy_id set when a copy is assigned
fees (if used)fee_id, member_id, loan_id, amount, currency, paid_atCreated at return when a loan was overdue
Core tables. Scroll sideways on a small screen.

5. The copy lifecycle and the hold queue

Copy states
StateMeaningMoves to
AVAILABLEOn the shelf at its current branchON_LOAN, ON_HOLD_SHELF, IN_TRANSIT, WITHDRAWN
ON_LOANChecked out to a memberAVAILABLE or ON_HOLD_SHELF or IN_TRANSIT at check-in; LOST after a long overdue period
IN_TRANSITTravelling to another branch for a hold or to its home branchON_HOLD_SHELF or AVAILABLE on arrival
ON_HOLD_SHELFWaiting for a named member until a pickup deadlineON_LOAN by that member, or back to the queue when it expires
LOST, WITHDRAWNOut of circulationRarely back to AVAILABLE when found
Copy states. Scroll sideways on a small screen.

When a copy is checked in, look up the oldest active hold for its title. If there is one, assign the copy to it: if the pickup branch is this branch, the copy goes to the hold shelf; otherwise it goes in transit. If no one is waiting and the copy is away from its home branch, it may be sent home or kept where it is (a "floating" collection); that is a library policy to ask about. When a hold expires uncollected, the copy is offered to the next person in line.

from collections import deque

class Library:
    def __init__(self, loan_limit=5):
        self.copy_title, self.status = {}, {}   # copy_id -> title_id / state
        self.loans = {}                          # copy_id -> member_id
        self.holds = {}                          # title_id -> deque of member_ids
        self.ready = {}                          # copy_id -> member it waits for
        self.loan_count, self.limit = {}, loan_limit

    def checkout(self, member, copy_id):
        state = self.status[copy_id]
        if state == "ON_HOLD_SHELF" and self.ready[copy_id] != member:
            raise ValueError("held for another member")
        if state not in ("AVAILABLE", "ON_HOLD_SHELF"):
            raise ValueError("not available: " + state)
        if self.loan_count.get(member, 0) >= self.limit:
            raise ValueError("loan limit reached")
        self.status[copy_id], self.loans[copy_id] = "ON_LOAN", member
        self.ready.pop(copy_id, None)
        self.loan_count[member] = self.loan_count.get(member, 0) + 1

    def check_in(self, copy_id):
        member = self.loans.pop(copy_id)
        self.loan_count[member] -= 1
        self.status[copy_id] = "AVAILABLE"
        self._serve_next_hold(copy_id)

    def _serve_next_hold(self, copy_id):
        q = self.holds.get(self.copy_title[copy_id])
        if q:                                     # first in line gets this copy
            self.ready[copy_id] = q.popleft()
            self.status[copy_id] = "ON_HOLD_SHELF"
The core rules as a small object model (run with python3 and random operation tests).

The sketch leaves out branches and transit to stay short. In the database version, each method is one transaction: checkout updates the copy with a condition on its expected status, inserts the loan, and increments the member's loan count with a condition that it stays under the limit. If any of those affect no row, the transaction rolls back and the desk shows the reason. A partial unique index on open loans per copy is a second line of defence.

6. The architecture

  1. Users
    • Public catalogue web and app
    • Staff desks
    • Self-service kiosks
  2. API
    • API gateway with staff and member roles
  3. Services
    • Catalogue search
    • Circulation (loans, returns, holds)
    • Scheduled jobs
  4. Data
    • Relational database plus replica
    • Search index
  5. Outbound
    • Notification service (email, text)
    • Branch offline queue
A library network's services. Members use a public catalogue website and app; staff desks and self-service kiosks in each branch use a circulation client. Both reach an API layer. A catalogue search service answers searches from a search index fed by changes to titles and copies. A circulation service handles checkout, check-in, renewals and holds against the main relational database. A scheduled jobs service runs due-date reminders, hold expiry and overdue processing, and hands messages to a notification service for email and text. Each branch client keeps a local offline queue for checkouts and check-ins during network outages.

7. Deep dives

  • Search. Full-text search over titles, authors and subjects belongs in a search index, not LIKE queries. Availability per branch changes constantly, so show it from the database at read time for the few titles on the results page, or update it in the index from circulation events.
  • Renewals. Allowed only if no active hold exists for the title, the member is in good standing and the renewal count is under the limit. Check all three in the renew transaction.
  • Scheduled work. Reminders a few days before the due date, hold-shelf expiry each morning, and long-overdue copies marked lost: all are jobs over indexed due dates. The patterns are in design a job scheduler, and reminders go through a notification system.
  • Branch outages. If a branch loses its connection, desks keep working: checkouts and check-ins are queued locally with timestamps and replayed when the link returns. Conflicts are rare (one physical copy is in one place) and are resolved by trusting the physical scan, then flagging any hold that was affected.
  • History and privacy. Libraries are often careful about how long they keep who borrowed what. Keep loan history only as long as policy allows, and separate statistics (counts per title) from member identity.
  • Audit. Staff overrides (waiving a fee, extending a due date) should leave a record of who did it. An append-only log of circulation events also makes reports easy; see CQRS and event sourcing for when that log becomes the source of truth.

8. What breaks, and what you do about it

Failure modes
FailureEffectMitigation
Two kiosks scan the same copyRisk of two loansConditional update on copy status; second scan gets "already on loan"
Member borrows at two kiosks at once near the limitLimit exceeded by oneConditional increment of active_loan_count in the same transaction
Branch network downDesk cannot reach the serverLocal queue, replayed in order; holds re-evaluated after replay
Hold assigned but copy never arrivesMember waits indefinitelyTransit timeout raises a staff task and reassigns another copy
Reminder job runs twiceDuplicate emailsRecord sent reminders per loan and due date; send only once
Failure modes. Scroll sideways on a small screen.

9. Trade-offs to discuss

  • One database or several services. At this scale one database keeps every rule a local transaction; services can still be split in code.
  • Fair queue or fastest pickup. Strict order serves the longest waiter; assigning a copy already at the pickup branch is faster and saves transport. Ask which the library prefers.
  • Offline tolerance or strict checks. Lending during an outage keeps branches open but can briefly break a loan limit or a hold; most libraries accept that.

10. How to talk through it in the interview

Fictional example

A returned book with a queue behind it
Interviewer
A member returns a copy at the north branch. Three people have holds on that title. What happens?
Candidate
Check-in closes the loan and looks up the oldest active hold for the title. Its pickup branch is south, so the copy is assigned to that hold and marked in transit, and the desk screen says to send it south. On arrival it becomes on hold shelf with a pickup deadline and the member gets a message.
Interviewer
And if they never pick it up?
Candidate
The morning job expires the hold and offers the copy to the next person in line, who may have a different pickup branch, so it may travel again.
  • Draw the title and copy distinction in the first five minutes.
  • Walk through check-in with holds; it shows the state machine and the queue together.
  • Admit the scale is small and spend the time on correctness and outages.

Practicing this design with Natively

Modelling prompts reward clear naming more than clever infrastructure. Practise explaining the copy states and the hold queue in plain words on a mock call with Natively open; it transcribes as you go, can suggest an edge case such as a lost transit copy when the interviewer pauses, and can read a screenshot of your class diagram and point out a missing relationship. The notes afterwards help you tighten the explanation.

Questions people ask

How do you design a library management system?

Model titles separately from physical copies, give each copy a state machine (available, on loan, in transit, on the hold shelf, lost), keep a hold queue per title, and make checkout and check-in single transactions with conditional updates. At library scale one relational database is enough.

What classes are in a library management system design?

Typical ones are Title, Copy (or BookItem), Member, Loan, Hold, Branch and Fee if the library charges one. The important relationships are one title to many copies and one open loan per copy at most.

How do holds work in a library system?

Members place holds on a title, and the holds form a queue in the order placed. When any copy of that title is returned, it is assigned to the oldest active hold and either goes to the hold shelf or travels to that member's pickup branch, and an uncollected hold expires to the next in line.

How do you stop one book being checked out twice?

Checkout updates the copy only if its status is still available, or on the hold shelf for that member, inside the same transaction that creates the loan. A second scan finds no matching row and fails, and a unique index on open loans per copy backs it up.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP