Design Library Management (LLD)
1. Requirements
-
Functional
- Catalog books and copies; members borrow and return with due dates and fine policy.
- Enforce max concurrent loans per member; place hold when all copies are out.
- Librarian can add inventory, check in, and waive fines (audited).
-
Non-Functional
- Consistent loan state: a copy cannot be both available and checked out.
- Extensible fine rules and loan periods by book category or member tier.
-
Assumptions / Out of Scope
- Digital lending and DRM omitted; physical copies only.
2. Core Entities
| Entity | Responsibility | Key Attributes |
|---|---|---|
| Book | Title metadata | identifier, title, author, isbn, category |
| BookCopy | Circulation unit | copyId, bookId, status |
| Member | Borrower | identifier, name, activeLoans, tier |
| Loan | Checkout record | copy, member, start, due, status |
| Hold | Reservation queue | member, book, priority, createdAt |
| FinePolicy | Computes fines | rate per day, grace, caps |
| Catalog | Search and register | index of books and copies |
3. Class Diagram
Loading diagram…
4. State / Sequence Diagram (where relevant)
Loading diagram…
5. Design Patterns Applied
- Factory — Create
Loanwith validated clock and due date. Factory Method pattern. - Strategy —
FinePolicyandLoanPeriodPolicyby category. Strategy pattern. - Repository (conceptual) —
Catalogabstracts persistence; pair with Factory Method pattern for concrete stores when the pattern docs exist.
6. Implementation
Go
package library
type Book struct {
Identifier, Title, ISBN string
}
type BookCopy struct {
CopyID string
BookID string
Status string
}
type Member struct {
Identifier string
Name string
ActiveLoanCount int
}
type Circulation struct {
Catalog *Catalog
FineRules FinePolicy
}
func (circ *Circulation) Checkout(memberID, bookID string) (*Loan, error) { /* ... */ }
func (circ *Circulation) Return(copyID string) (fineCents int64, err error) { /* ... */ }JavaScript
class Catalog {
constructor() {
this.booksById = new Map();
this.copiesById = new Map();
}
addBook(book) { /* ... */ }
addCopy({ copyId, bookId }) { /* ... */ }
}
class CirculationService {
constructor({ catalog, finePolicy }) {
this.catalog = catalog;
this.finePolicy = finePolicy;
}
checkout({ memberId, bookId }) { /* ... */ }
returnCopy({ copyId }) { /* ... */ }
}7. Concurrency / Thread Safety
- Collisions: Two clerks checking out last available copy; concurrent return and renew.
- Granularity: Transaction wrapping copy status update and loan insert; DB unique constraint on active loan per copy.
- Go:
sync.Mutexper copy id in in-memory simulation.
8. Extensibility & Followups
- Inter-library loan as workflow with external partner ids.
- Notification scheduler on due soon and overdue.
- Edge cases: lost book, damaged return, membership suspension.
Last updated on
Spotted something unclear or wrong on this page?