ReviseAlgo Logo

LLD Interview Framework

How to Answer an LLD Problem

Master a structured 5-step framework to navigate Low-Level Design (LLD) interview questions smoothly from requirements gathering to clean, runnable code.

Last Updated: June 26, 2026 25 min read

Succeeding in a 45-60 minute Low-Level Design (LLD) or Object-Oriented Design (OOD) interview is not just about writing code. Interviewers want to evaluate your system design thinking, how you decompose complex requirements, your application of SOLID principles, and your ability to write clean, modular, and extensible code.

1. Learning Objectives

  • Master the structured 5-Step LLD Interview Framework.
  • Deconstruct vague problem statements into functional and non-functional requirements.
  • Identify core domain entities (classes) and behaviors (methods) systematically.
  • Determine relationships (composition vs. inheritance) and draw accurate UML diagrams.
  • Select and integrate appropriate GoF design patterns to make code extensible.
  • Write clean, runnable, and testable code within the interview time limits.

2. Problem & Naive Solution

Imagine you are in an interview and the interviewer asks: "Design a Vending Machine."

The Naive Solution (Jumping Straight to Code)

A common mistake candidates make is immediately opening their IDE or writing code on the whiteboard without clarifying requirements or designing the class structure:

3. Issues with the Naive Approach

  • Tightly Coupled State Transitions: If you need to add a new state (e.g., OutOfOrder or Dispensing), you must rewrite the conditional logic across all methods. This violates the Open/Closed Principle, making the code fragile and error-prone.
  • Unclear Scope: The developer did not clarify what coins are accepted, how inventory is managed, or what happens when a product is out of stock. This leads to missing requirements and wasted development time.
  • Poor Modularity: A single class manages states, balances, and product dispensing, violating the Single Responsibility Principle.

4. Real-world Analogy

Think of building a house:

* Naive Builder: Immediately starts laying bricks without a blueprint. Halfway through, they realize they forgot the plumbing layout. They must tear down walls to install pipes, wasting time and materials.
* Professional Architect: Meets with the client to define space requirements (Step 1), lists the necessary rooms and resources (Step 2), draws blueprints and layouts (Step 3), selects construction templates (Step 4), and only then starts building (Step 5).

5. Theory: The 5-Step LLD Interview Framework

To succeed in LLD interviews, follow this structured 5-step framework:

Step 1: Clarify Requirements & Scope (5-10 mins)

LLD questions are intentionally open-ended. Your first task is to gather functional requirements, list system constraints, and establish non-functional guidelines:

  • Functional Requirements: What *must* the system do? (e.g., "The vending machine must accept coins and bills, allow product selection, dispense products, and return change.")
  • Constraints: What is out of scope? (e.g., "We will assume card payments and inventory restocking notifications are out of scope for the initial version.")
  • Non-functional Guidelines: What are the design priorities? (e.g., "The system must be extensible to support new states and payment methods, and must be thread-safe.")

Step 2: Define Core Entities (10 mins)

Identify key classes (nouns) and behaviors (verbs) systematically from the requirements:

  • Nouns (Classes): VendingMachine, State, Product, Inventory, Coin.
  • Verbs (Methods): insertCoin(), selectProduct(), dispense(), cancelTransaction().

Step 3: Design Relationships & UML (10-15 mins)

Map class relationships: inheritance, composition, association. Add multiplicities (e.g., VendingMachine contains 1 Inventory; Inventory contains many Products).

Step 4: Select Design Patterns (5 mins)

Integrate design patterns to make code extensible. For example:

  • State Pattern: Ideal for vending machines, parking gates, or order workflows where behavior changes based on state.
  • Strategy Pattern: Useful for routing payment fees or discount strategies dynamically.
  • Factory Method: Perfect for instantiating products or vehicles.

Step 5: Write Clean Code (20 mins)

Translate your UML design into clean, runnable code. Implement robust error handling (avoid returning nulls) and create a main demo runner to demonstrate your classes.

6. UML Class Diagram: Vending Machine State Pattern

Below is the UML class diagram for the vending machine design. The VendingMachine class delegates operations to the polymorphic State interface, decoupling states from one another.

7. Complete Code (Vending Machine Case Study)

This is a complete, clean, and runnable implementation of the Vending Machine design using the State Pattern.

8. Code Walkthrough

Let's review the key elements of the Vending Machine case study:

  • Polymorphic Delegation: The VendingMachine context delegator calls currentState.insertCoin(this, amount). It has no knowledge of what concrete state class is active. This decouples transition logic from the main class, satisfying the Open/Closed Principle.
  • No Conditional Chains: We have completely eliminated the nested if-else blocks present in the naive solution. Adding a new state is as simple as implementing the State interface and updating transitions.

9. Best Practices

  • State Your Assumptions Proactively: At the start of the interview, state your assumptions clearly (e.g. "Assuming one vehicle type per parking spot"). Write them down on the board to avoid misalignment.
  • Prioritize Modularity Over Performance: In LLD interviews, clean interfaces, loose coupling, and SOLID compliance are significantly more important than minor micro-optimizations.

10. Common Mistakes

  • Jumping Into Coding Immediately: Coding without clarifying the scope. This often leads to over-engineering or building the wrong solution.
  • Force-Fitting Design Patterns: Applying complex patterns (e.g., using a Visitor pattern where a simple strategy would suffice), adding unnecessary complexity.

11. Interview Discussion

Q: When should you prefer Composition over Inheritance during LLD designs?
Answer: Use Composition (has-a relationship) by default. It provides runtime flexibility (you can change strategies or state implementations dynamically) and avoids the tight coupling and deep hierarchies associated with Inheritance (is-a).
Q: How do you handle thread-safety in a Vending Machine context?
Answer: In a concurrent system, multiple threads might attempt to purchase items or restock inventory simultaneously. You should synchronize operations on the VendingMachine instance or use thread-safe data structures like ConcurrentHashMap for inventory and AtomicDouble / ReentrantLock to protect balance modifications.

12. Practice Exercises

  • Easy: Apply the 5-step framework to design a simple Stack Overflow system (Users, Questions, Answers).
  • Medium: Design a thread-safe Parking Lot system supporting multiple vehicle types and parking spot size allocations.
  • Hard: Design an Online Movie Ticket Booking System (like BookMyShow). Handle concurrent seat selection and booking transactions.

13. Challenge Problem

Apply the 5-step framework to design an Enterprise Ride-Sharing Dispatcher (like Uber). The dispatcher matches riders with nearby drivers based on distance and rating metrics. It must handle concurrent ride requests and driver status updates. Draw the UML class diagram and implement a thread-safe simulation in Java, Python, or C++.

14. Summary & Cheat Sheet

Framework Step Key Action & Time Allocation
1. Clarify Gather functional requirements, define scope and constraints (5-10 mins).
2. Define Entities Identify classes (nouns) and behaviors (verbs) (10 mins).
3. Design UML Determine class relationships: composition, association (10-15 mins).
4. Select Patterns Apply GoF design patterns (State, Strategy, Factory) (5 mins).
5. Write Code Write clean, modular, and thread-safe code with verification tests (20 mins).

15. Quiz

1. What is the first step of the LLD answering framework?

A) Write code immediately
B) Clarify requirements, scope, and constraints (Correct)
C) Draw UML diagrams

2. Which design pattern is ideal for managing states in a Vending Machine?

A) Singleton Pattern
B) State Pattern (Correct)
C) Decorator Pattern

3. Why is composition generally preferred over inheritance in LLD?

A) It is faster to execute
B) It reduces coupling and provides runtime flexibility (Correct)
C) It uses less memory

4. What does the Single Responsibility Principle state?

A) A class should have only one reason to change, meaning it should perform exactly one responsibility (Correct)
B) Only one thread can run at a time
C) All variables must be private

5. What is the main benefit of identifying "verbs" during Step 2 of the framework?

A) Finding class fields
B) Defining method signatures and behaviors (Correct)
C) Determining database schemas

6. How should you handle unexpected exceptions or edge cases in your code during the interview?

A) Ignore them to save time
B) Use custom exceptions and validation checks to write robust code (Correct)
C) Return null values

7. What is the recommended time allocation for the coding step in a 60-minute interview?

A) 5 minutes
B) 20 minutes (Correct)
C) 50 minutes

8. Which design pattern is best suited for routing different payment fee strategies?

A) Strategy Pattern (Correct)
B) Observer Pattern
C) Command Pattern

9. What does the "O" in SOLID stand for?

A) Object-Oriented
B) Open/Closed Principle (Correct)
C) Optimistic Concurrency

10. Why is it important to talk out loud during an LLD interview?

A) To keep the interviewer awake
B) To share your design choices, assumptions, and trade-offs in real-time (Correct)
C) To speed up execution

16. Next Lesson Preview

In the next lesson, we will cover Clean Code & Refactoring. We will explore code smells, learn refactoring techniques like Extract Method, and study how to write readable, self-documenting code!