Bird
0
0
LLDsystem_design~25 mins

Class design (Book, Member, Librarian, Loan) in LLD - System Design Exercise

Choose your learning style9 modes available
Design: Library Management System
Design the core classes and their relationships for managing books, members, librarians, and loans. Exclude UI and database implementation details.
Functional Requirements
FR1: Allow members to borrow and return books
FR2: Track which books are loaned and their due dates
FR3: Librarians can add, update, and remove books
FR4: Members can view their loan history and current loans
FR5: Support multiple members and librarians
Non-Functional Requirements
NFR1: Handle up to 10,000 members and 100,000 books
NFR2: Operations should be efficient for quick lookups
NFR3: Ensure data consistency for loans and returns
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
Book class with details like title, author, ISBN
Member class with personal info and loan records
Librarian class with permissions to manage books
Loan class to represent borrowing details
Design Patterns
Association between Member and Loan
Inheritance if Librarian and Member share common user attributes
Encapsulation to protect class data
Use of methods to perform borrow and return actions
Reference Architecture
Library Management System Classes

+----------------+       +----------------+       +----------------+
|     Book       |       |    Member      |       |   Librarian    |
+----------------+       +----------------+       +----------------+
| - bookId       |       | - memberId     |       | - librarianId  |
| - title        |       | - name         |       | - name         |
| - author       |       | - email        |       | - email        |
| - ISBN         |       | - loans: List  |       |                |
| - isAvailable  |       +----------------+       +----------------+
+----------------+               |                          |
         ^                       |                          |
         |                       |                          |
         |                       |                          |
         |                       |                          |
         |                       |                          |
         |                       |                          |
         |                       v                          v
         |               +----------------+
         |               |      Loan      |
         |               +----------------+
         |               | - loanId       |
         |               | - book: Book   |
         |               | - member: Member|
         |               | - loanDate     |
         |               | - dueDate      |
         |               | - returnDate   |
         |               +----------------+
Components
Book
Class
Represents a book with details and availability status
Member
Class
Represents a library member with personal info and loan records
Librarian
Class
Represents a librarian who manages books
Loan
Class
Represents a loan record linking a book and a member with dates
Request Flow
1. Member requests to borrow a book
2. System checks if the book is available
3. If available, create a Loan object with loanDate and dueDate
4. Mark the book as not available
5. Add the loan to the member's loan list
6. Member returns the book
7. System updates the Loan with returnDate
8. Mark the book as available again
9. Librarian adds or updates book details in the system
Database Schema
Entities: - Book(bookId PK, title, author, ISBN, isAvailable) - Member(memberId PK, name, email) - Librarian(librarianId PK, name, email) - Loan(loanId PK, bookId FK, memberId FK, loanDate, dueDate, returnDate) Relationships: - One Member can have many Loans (1:N) - One Book can have many Loans over time (1:N) - Loan links one Book and one Member
Scaling Discussion
Bottlenecks
Searching books by title or author becomes slow with many books
Tracking loans for many members can cause performance issues
Concurrent borrow requests for the same book may cause conflicts
Solutions
Use indexing on book attributes for fast search
Paginate loan records and cache frequent queries
Implement locking or transactions to prevent double borrowing
Interview Tips
Time: Spend 10 minutes understanding requirements and clarifying scope, 20 minutes designing classes and relationships, 10 minutes discussing scaling and improvements, 5 minutes summarizing.
Explain class responsibilities clearly
Show relationships and how they support requirements
Discuss how to handle book availability and loan tracking
Mention data consistency and concurrency handling
Highlight how the design can scale with more users and books