A low-level design (LLD) interview asks you to design the classes behind a small system and usually write working code for it, all in about 45 minutes. The interviewer watches how you get there as much as what you produce: do you narrow the problem, choose classes that own the right data, and leave clean places to extend? Having one plan you run every time stops you from typing code before the design is settled.
This note walks through that plan on a single example, a library book-lending system, so you can see each phase build on the last.
The plan on a clock#
Think of the interview as a 45-minute clock and give each phase a window. The windows are a guide, not a contract, but checking the clock keeps you from spending half the interview on requirements.
| Phase | Clock | What you leave on the board |
|---|---|---|
| 1. Pin the problem | 0–6 min | Use cases, rules, an out-of-scope list |
| 2. Sketch the model | 6–12 min | Classes, what each owns, one coordinator |
| 3. Shape the API | 12–22 min | Enums, interfaces, signatures with pass |
| 4. Build the main path | 22–38 min | Working code for the core flow, then the failures |
| 5. Stress and extend | 38–45 min | A traced run, fixed bugs, extension points |
Most designs need the same few imports, so start the file with them:
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from datetime import date, timedelta
from enum import Enum
Phase 1: Pin the problem (0–6 min)#
The prompt is usually one vague line: "Design a library system." Your job in this phase is to turn it into a short list of things the code must do, and an equally clear list of things it won't.
Who uses it, and what they do#
Name the actors first, then the actions each one needs. Each action becomes a public method later.
- Member: borrows a copy, returns it, places a hold on a book that is out.
- Librarian: adds copies, marks a copy lost.
Clarifying questions: VAME#
VAME is a mnemonic for the four kinds of question worth asking:
| Letter | Ask | Library example |
|---|---|---|
| Variations | "Are they all the same?" | Do students and staff get different loan limits? |
| Algorithms | "How does it decide or calculate?" | How is a late fee worked out? |
| Multiplicity | "Is there only one?" | Several copies of the same book? Several branches? |
| Exceptions | "What if it's full, missing, invalid?" | Member at their limit, copy already out, unpaid fees |
Write the rules down#
Turn the answers into numbered rules you can point back to:
- A member can hold at most 5 loans at once.
- A loan lasts 14 days. Each late day costs $0.25.
- A member with more than $10 in unpaid fees cannot borrow.
- When a copy comes back and the book has holds, the copy goes to the first member in the hold queue.
Say what you won't build#
Close the phase by naming what is out of scope: search, payments, multiple branches, a UI, persistence. Say it as a check, not an announcement: "I'll leave search, payments and branches out and focus on lending and holds. Does that match what you want?"
Phase 2: Sketch the model (6–12 min)#
Now turn the rules into classes. Nouns in the rules are good candidates, but each one has to earn its place by owning some data.
| Class | Owns |
|---|---|
Book |
ISBN, title, the queue of members waiting for it |
Copy |
Copy ID, which book it is, its status |
Member |
Member ID, tier, current loans, unpaid fees |
Loan |
Which copy, which member, due date, return date |
Library |
All books, copies and members; runs every use case |
Two questions settle the rest:
- Who coordinates? One class drives each use case and calls the others. Here that is
Library. Members and copies don't call each other directly. - Where does each rule live? Put a rule in the class that owns the data it checks. "At most 5 loans" reads
Member's loans, soMemberanswerscan_borrow(). The fee rule varies, so it goes behind an interface (next phase).
For how classes can relate (owns, uses, is made of), see Relationships.
Phase 3: Shape the API (12–22 min)#
Write the skeleton before any logic: enums, interfaces, fields and method signatures, with pass for the bodies. If the skeleton reads well, the implementation is mostly filling in blanks.
Enums for fixed sets#
A copy is only ever in one of a few states, so make that explicit instead of passing strings around.
class CopyStatus(Enum):
AVAILABLE = "available"
ON_LOAN = "on_loan"
RESERVED = "reserved" # held for the next member in the queue
LOST = "lost"
Interfaces for what varies#
Anything the interviewer might change later, or that you scoped down, goes behind an abstract class with one simple version behind it. The fee rule is the obvious one here.
class FeePolicy(ABC):
@abstractmethod
def fee_for(self, loan: "Loan", returned_on: date) -> float:
pass
class FlatDailyFee(FeePolicy):
def __init__(self, per_day: float = 0.25):
self.per_day = per_day
def fee_for(self, loan: "Loan", returned_on: date) -> float:
late_days = (returned_on - loan.due_on).days
return max(late_days, 0) * self.per_day
The core classes#
Give each class its fields and the methods from Phase 1. Say which data structure you chose and why, for example "copies in a dict keyed by ID, so a return is an O(1) lookup".
@dataclass
class Book:
isbn: str
title: str
holds: list[str] = field(default_factory=list) # member IDs, in order
@dataclass
class Copy:
copy_id: str
book: Book
status: CopyStatus = CopyStatus.AVAILABLE
@dataclass
class Member:
member_id: str
max_loans: int = 5
loans: list["Loan"] = field(default_factory=list)
unpaid_fees: float = 0.0
def can_borrow(self) -> bool:
return len(self.loans) < self.max_loans and self.unpaid_fees <= 10
@dataclass
class Loan:
copy: Copy
member: Member
due_on: date
class Library:
def __init__(self, fee_policy: FeePolicy):
self.fee_policy = fee_policy
self.books: dict[str, Book] = {}
self.copies: dict[str, Copy] = {}
self.members: dict[str, Member] = {}
def check_out(self, member_id: str, copy_id: str) -> Loan:
pass
def return_copy(self, copy_id: str, returned_on: date) -> float:
pass
def place_hold(self, member_id: str, isbn: str) -> None:
pass
Phase 4: Build the main path (22–38 min)#
Ask first whether the interviewer wants working code or pseudocode. Then implement one use case all the way through before you start the next, in this order:
- Say it in plain words first. "Look up the member and the copy, check both can take part, create the loan, update both sides."
- Write the success path. Get the normal case working end to end.
- Add the failures. Unknown IDs, a copy that is not available, a member who can't borrow. Fail loudly with a clear error rather than returning
None. - Keep both sides in sync. A loan touches the copy and the member. Update both, or neither.
def check_out(self, member_id: str, copy_id: str) -> Loan:
member = self.members.get(member_id)
copy = self.copies.get(copy_id)
if member is None or copy is None:
raise KeyError("unknown member or copy")
if copy.status is not CopyStatus.AVAILABLE:
raise ValueError(f"copy {copy_id} is {copy.status.value}")
if not member.can_borrow():
raise PermissionError("loan limit reached or fees unpaid")
loan = Loan(copy, member, due_on=date.today() + timedelta(days=14))
copy.status = CopyStatus.ON_LOAN
member.loans.append(loan)
return loan
Hand off anything that isn't the point of the exercise. The fee math lives in FeePolicy, so return_copy just calls self.fee_policy.fee_for(...).
Phase 5: Stress and extend (38–45 min)#
Use the last few minutes to show the design holds up.
Trace a hard case#
Pick a scenario that crosses several rules and walk it through the code out loud. For the library: a member returns a copy 3 days late, and the book has two members waiting. Check that the fee is $0.75, the loan leaves the member's list, and the copy becomes RESERVED for the first member in the queue, not AVAILABLE. For each if, name one input that takes it and one that skips it.
Name the extension points#
Interviewers often finish with "what if…" questions. Answer by pointing to where the change goes, not by editing what works:
- Staff get 10 loans and no fees: a staff
Memberwithmax_loans=10, and aNoFeepolicy. - Email when a hold is ready: a
Notifierinterface thatLibrarycalls when a copy becomesRESERVED.
That is the Open/Closed Principle in practice: new behavior comes in as new classes.
Bring back what you scoped out#
Mention concurrency even if you skipped it. Two members checking out the last copy at the same moment is a check-then-act race on copy.status. A lock per copy, or a conditional database update, closes it.
Key takeaways#
- Run the same five phases every time, and watch the clock: pin the problem, sketch the model, shape the API, build the main path, stress and extend.
- Turn the prompt into numbered rules and an out-of-scope list before designing anything. VAME helps you find the questions.
- A class earns its place by owning data. Put each rule in the class that owns what it checks, and pick one coordinator.
- Write the skeleton first: enums for fixed states, interfaces for what varies, signatures with
pass. - Build one use case end to end, add the failures, and keep related objects in sync.
- Finish by tracing a hard case and showing where new requirements would plug in.