LLD Hub
lldoopobserver

How to Design a Library Management System | LLD Interview Guide

Design a library system with book borrowing, fine calculation, and notifications. Classic beginner LLD problem asked in entry-level SDE interviews.

8 April 2025·7 min read

Practice this problem

Library Management System — get AI-scored feedback on your solution

Solve it →

The Library Management System is a classic beginner-to-intermediate LLD problem that tests your ability to model relationships, lifecycle states, and notification patterns. It's commonly asked in SDE-1 and SDE-2 interviews at product-based companies.

Core Entities

  • Book — ISBN, title, author, genre (one Book can have many BookItems)
  • BookItem — a physical copy of a Book, has a barcode and status
  • Member — can borrow up to 3 books, has active loans
  • Librarian — manages inventory
  • Loan — member, bookItem, borrowDate, dueDate, returnDate
  • Reservation — a member waiting for a BookItem to become available
  • Fine — calculated when a book is returned late

Key Distinction: Book vs BookItem

class Book {
  isbn: string;
  title: string;
  author: string;
  copies: BookItem[];  // multiple physical copies
}

class BookItem {
  barcode: string;
  book: Book;
  status: BookItemStatus;  // AVAILABLE | BORROWED | RESERVED | LOST
}

Loan Management

class LoanService {
  borrowBook(member: Member, bookItem: BookItem): Loan {
    if (member.activeLoans >= 3) throw new Error("Borrow limit reached");
    if (bookItem.status !== BookItemStatus.AVAILABLE) throw new Error("Not available");

    bookItem.status = BookItemStatus.BORROWED;
    const due = new Date();
    due.setDate(due.getDate() + 14); // 14-day borrow period

    return this.loanRepo.create({ member, bookItem, dueDate: due });
  }

  returnBook(loan: Loan): Fine | null {
    loan.bookItem.status = BookItemStatus.AVAILABLE;
    loan.returnDate = new Date();

    const daysLate = daysBetween(loan.dueDate, loan.returnDate);
    if (daysLate > 0) return new Fine(loan, daysLate * 5); // ₹5/day

    this.notifyReservations(loan.bookItem); // Observer pattern
    return null;
  }
}

Observer for Reservations

class LoanService {
  private notifyReservations(bookItem: BookItem) {
    const next = this.reservationRepo.findFirst(bookItem.book.isbn);
    if (next) {
      bookItem.status = BookItemStatus.RESERVED;
      this.notificationService.notify(next.member, "Your reserved book is available!");
    }
  }
}

Common Questions

  • "How do you handle renewals?" → Extend dueDate if no active reservation on the book
  • "What if a member has unpaid fines?" → Block borrowing until fine is cleared
  • "How do you search books?" → Index by title, author, ISBN; use BookCatalog service

Ready to practice?

Submit your solution and get AI-scored feedback on OOP, SOLID principles, design patterns, and code quality.

Solve Library Management System