LLD Template
Step-by-step approach for Low-Level Design interviews (45-60 minutes)
Interview Timeline
1. Requirements
0-5 min
Clarify problem, identify actors, core features
2. Use Cases
5-10 min
Define primary use cases & user flows
3. Class Diagram
10-25 min
Design classes, relationships, attributes
4. Design Patterns
25-35 min
Apply patterns, justify choices
5. Code Key Methods
35-50 min
Implement critical functionality
6. Discussion
50-60 min
Trade-offs, extensions, edge cases
Phase 1: Requirements Gathering (0-5 min)
Goals
Understand the problem scope
Identify actors (users, systems)
List core features
Don't: Jump into classes before understanding requirements
###Template Questions
Example: Design a Parking Lot System
Phase 2: Use Cases (5-10 min)
Define Primary Use Cases
Template:
Identify Edge Cases:
Phase 3: Class Diagram (10-25 min)
Step 1: Identify Nouns (Entities)
From requirements, extract nouns:
Parking Lot
Parking Spot
Vehicle (Car, Bike, Truck)
Ticket
Payment
Step 2: Define Classes
Core Classes:
Step 3: Define Relationships
Relationships:
UML Diagram (text representation):
Phase 4: Design Patterns (25-35 min)
Common Patterns for LLD
1. Singleton (Parking Lot Manager)
Why: Only one parking lot instance needed.
2. Factory (Vehicle Creation)
Why: Encapsulate object creation logic.
3. Strategy (Fee Calculation)
Why: Different pricing strategies (hourly, flat, weekend discounts).
4. Observer (Spot Availability Notification)
Why: Notify systems (display boards, mobile apps) when spots become available.
Phase 5: Code Key Methods (35-50 min)
Implementation
parkVehicle():
findAvailableSpot():
calculateFee():
Phase 6: Discussion (50-60 min)
Trade-offs
Q: Why use Strategy pattern for pricing?
A: Allows flexible pricing (hourly, flat, peak/off-peak) without modifying ParkingLot class. Easy to add new strategies (member discounts, weekend rates).
Q: Why Singleton for ParkingLot?
A: Only one parking lot instance needed. Ensures centralized state management. However, makes testing harder (can inject mock instead).
Q: How to handle concurrency (multiple customers parking simultaneously)?
A: Use synchronized blocks or locks when assigning spots:
Extensions
Q: How would you add a reservation system?
A: Add
Reservationclass withreservationTime,vehicle,spotType. ModifyfindAvailableSpot()to check reserved spots.
Q: What if we need multiple parking lots in different cities?
A: Remove Singleton, use Factory to create ParkingLot instances. Add
Locationfield.
SOLID Principles Checklist
S - Single Responsibility
ParkingSpot only manages spot state
Ticket only tracks parking session
PricingStrategy only calculates fees
O - Open/Closed
Can add new VehicleTypes without modifying ParkingSpot
Can add new PricingStrategies without modifying Ticket
L - Liskov Substitution
Car, Bike, Truck can replace Vehicle without breaking code
I - Interface Segregation
PricingStrategy interface has only one method (focused)
D - Dependency Inversion
ParkingLot depends on PricingStrategy interface, not concrete implementations
Common LLD Problems
Parking Lot (this example)
Elevator System
Library Management
ATM Design
Chess Game
Hotel Booking System
Vending Machine
Online Shopping Cart
Snake & Ladder
Tic-Tac-Toe
Interview Tips
Do's:
Ask clarifying questions
Start with simple classes, then refine
Explain design pattern choices
Code at least 2-3 key methods
Use meaningful names (not FooManager, BarService)
Don'ts:
Don't code before designing classes
Don't over-engineer (avoid 10 patterns for simple problem)
Don't forget edge cases (null checks, concurrency)
Don't use getters/setters for everything (violates encapsulation)
Example Answer Template:
"I'll design a parking lot with classes for ParkingLot, ParkingSpot, Vehicle (with Car/Bike/Truck subclasses), and Ticket. I'll use Factory pattern to create vehicles, Strategy pattern for flexible pricing, and Observer pattern to notify when spots become available. The key methods are parkVehicle() which finds an available spot atomically, and calculateFee() which computes cost based on the pricing strategy."
Last updated