A Step-by-Step Method for Any LLD Problem
Learn a seven-step method you can use on any low-level design problem, from asking the first question to discussing extensions, with a complete library example.
The hardest moment in an LLD interview is the first minute. The interviewer says "design a library system", the board is empty, and your mind goes blank. A method fixes that. If you know what to do first, second and third, you never face an empty board; you simply move to the next step.
This lesson gives you a seven-step method that works for almost every LLD problem. We will first look at the steps, then run through them on one complete example, a small library system, so you see how each step feeds the next.
01The seven steps at a glance
The times are a guide for a 45-minute round. The important point is the shape: a quarter of the time is spent before you draw anything, and only about a third is spent on code. Many people reverse this and run out of time before they have a design worth coding.
Here is the method in one sentence each:
- Clarify what the system must do, and what it will not do.
- Find the entities: the main things in the problem, which become classes.
- Assign responsibilities: decide which class does which job.
- Draw the class diagram: the classes and how they connect.
- Walk through two or three real scenarios on your diagram to test it.
- Write the key code: the important interfaces and methods only.
- Discuss extensions and trade-offs: how the design handles change.
Now let us walk through all seven with a real example. The problem: "Design a library system."
02Step 1: Clarify the requirements
Never design from the one-line problem. Ask questions until you can write a short, clear list. Good questions are about who uses the system, what they do, which rules apply and what is out of scope.
For the library, you might ask:
- Who uses the system? (Members who borrow books. Assume one librarian-run counter for now.)
- Can the library hold many copies of the same title? (Let us say each book record is one physical copy.)
- How many books can a member borrow at the same time? (Three.)
- How long can a book be kept? (14 days.)
- Can members search for books? (Yes, by title.)
- What happens when a book is returned late? (Out of scope for now; we will treat it as an extension.)
Write the answers down as a list the interviewer can see:
| Type | Requirement |
|---|---|
| Must do | Members can search books by title |
| Must do | A member can borrow an available book |
| Must do | A member can hold at most 3 books at a time |
| Must do | A loan lasts 14 days |
| Must do | A member can return a borrowed book |
| Out of scope | Fines, reservations, payments, several copies of one title |
This table is your contract. If the interviewer later asks for fines, you can say "that was out of scope, but here is how we would add it", which is a strong answer.
03Step 2: Find the entities
An entity is a main "thing" in the problem. The easiest way to find them is to read your requirements and underline the nouns.
A member can search books by title. A member can borrow an available book and holds at most 3 books. A loan lasts 14 days.
The nouns are: member, book, title, loan, library. Not every noun becomes a class. A title is just a piece of text that belongs inside Book, so it is a field, not a class. After this filter we keep: Member, Book and Loan. We will also need one place to coordinate the actions, which we will call LibraryService. The next lesson explains in detail how to decide what becomes a class.
04Step 3: Assign responsibilities
A responsibility is something a class knows or does. Now underline the verbs: search, borrow, return, check availability, hold. Then ask of each one, "which class owns the information needed to do this?"
| Class | What it knows | What it does |
|---|---|---|
Book | Its title and ISBN, and whether it is borrowed | Says if it is available; marks itself borrowed |
Member | Its name and its current loans | Decides if it can borrow another book (the limit of 3) |
Loan | Which book, which member, due date, return date | Says if it is overdue; closes itself on return |
LibraryService | Where books and members are stored | Coordinates borrow, return and search |
Notice the pattern: each rule lives next to the data it needs. The limit of 3 books belongs in Member, because Member knows how many loans it has. This habit keeps classes small and clear.
05Step 4: Draw the class diagram
Now connect the classes. A Member can have many Loan objects. Each Loan refers to exactly one Book. LibraryService uses all three. Here is our first draft:
Do not draw every getter and setter. Show the fields and methods that explain the design. Lesson 4 explains the lines and symbols in detail.
06Step 5: Walk through the flows
This step is the one most people skip, and it is where good designs are made. Take two or three real scenarios and "run" them on your diagram, speaking out loud.
Scenario A: borrow an available book. LibraryService finds the member and the book. It asks the member canBorrow(). It asks the book isAvailable(). It creates a Loan, marks the book as borrowed and adds the loan to the member. Every method we need exists on the diagram.
Scenario B: borrow when the member already holds 3 books. canBorrow() returns false, and we refuse. Good.
Scenario C: return a book. LibraryService finds the loan and calls close() on it, which records the return date. Then the book must become available again... but our Book only has markBorrowed(). We found a gap. We need a markReturned() method on Book. Adding it now costs ten seconds; discovering it after you wrote all the code would cost much more.
That is the whole purpose of the walk-through: finding missing methods and classes while the design is still cheap to change.
07Step 6: Write the key code
Now write only the important code: the interfaces and the one or two methods that hold real logic. For the library, the heart is borrowBook. We skip constructors, getters and storage details.
public Loan borrowBook(String memberId, String isbn) {
Member member = members.find(memberId);
Book book = books.find(isbn);
if (!member.canBorrow()) {
throw new IllegalStateException("Borrow limit reached");
}
if (!book.isAvailable()) {
throw new IllegalStateException("Book is already borrowed");
}
Loan loan = new Loan(member, book, LocalDate.now().plusDays(14));
book.markBorrowed();
member.addLoan(loan);
return loan;
}Read it like a sentence: find the member and the book, refuse if the rules are broken, otherwise create the loan, update the book and the member, and return the loan. Each rule is checked by the class that owns the data (canBorrow on Member, isAvailable on Book). LibraryService only coordinates.
08Step 7: Discuss extensions and trade-offs
Finish by showing that your design can grow. Pick the most likely new requirements and say what changes.
- "Add late fees." We add a
FeePolicyinterface and afee()calculation that usesLoan.isOverdue().Book,MemberandborrowBookdo not change. - "Add reservations." We add a
Reservationclass that links a member and a book. Existing classes stay as they are, exceptLibraryService, which gains a method. - "Different limits for students and staff." We move the limit rule behind a
BorrowPolicyinterface, so each type of member can have its own rule.
You also mention a trade-off: "I kept the limit rule inside Member for simplicity. If rules grow, I would extract a policy class." Naming a trade-off shows maturity.
09Common mistakes
- Skipping step 1. You design for rules the interviewer never had in mind.
- Skipping step 5. You find missing methods only after the code is written.
- A diagram with every getter and setter. It hides the important parts. Show what explains the design.
- Writing all the code. Time runs out. Write the interface and the core method, and describe the rest.
- Working silently. The interviewer cannot give you credit for thoughts they cannot hear. Say what you are doing at each step.
10In the interview
- How much time should I spend on requirements? About five minutes of a 45-minute round. Enough to be sure of the rules, not so long that you have no time to design.
- What if the interviewer changes a requirement halfway through? Stay calm, because this tests your design. Say which class you would add or change and that the other classes stay as they are.
- What if I realise my diagram is wrong? Say so openly and fix it. Finding and correcting a mistake early is a good sign, not a bad one.
11Check your understanding
Quiz · 4 questions
0 of 4 answered
1. In the library example, why do we walk through the return scenario before writing code?
2. Which of these is a good clarifying question for a vending machine problem?
3. Where does the rule 'a member can hold at most three books' belong in our design?
4. Halfway through, the interviewer adds a rule: late returns must pay a fine. What is the best first reaction?