Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Low Level Design (LLD) - Overview

What is Low Level Design?

Low Level Design (LLD) is the process of designing the internal structure of a system’s components at the class and object level. It focuses on how individual modules are implemented using OOP principles, design patterns, and clean code practices.

In an LLD interview, you’re asked to design the class structure for a specific component — think “Design a Parking Lot system” or “Design an Elevator system” — by creating classes, defining relationships, and applying design patterns.

What Interviewers Expect

1. Requirements Gathering (2-3 minutes)

  • Clarify functional requirements
  • Identify actors and use cases
  • Define scope boundaries

2. Class Identification (5-7 minutes)

  • Identify core classes (nouns in requirements)
  • Define attributes and methods
  • Establish relationships between classes

3. Design Patterns (3-5 minutes)

  • Apply appropriate design patterns
  • Justify why each pattern fits
  • Show awareness of trade-offs

4. Code Implementation (10-15 minutes)

  • Write key classes and interfaces
  • Implement core logic
  • Handle edge cases

5. Discussion (5 minutes)

  • SOLID principles applied
  • Extensibility considerations
  • Error handling strategy

OOP Principles Quick Reference

The Four Pillars

┌─────────────────────────────────────────────┐
│              OOP Principles                  │
├──────────┬──────────┬──────────┬────────────┤
│Encapsula │ Inherita │ Polymorp │ Abstraction│
│tion      │ nce      │ hism     │            │
├──────────┼──────────┼──────────┼────────────┤
│Hide      │ "is-a"   │ One      │ Hide       │
│internal  │ relation │ interface│ complex    │
│state     │ ship     │ many     │ details    │
│          │          │ forms    │            │
└──────────┴──────────┴──────────┴────────────┘
PrincipleWhatWhyExample
EncapsulationHide internal state, expose methodsControl access, reduce couplingPrivate fields + getters/setters
InheritanceChild class inherits from parentCode reuse, hierarchyCar extends Vehicle
PolymorphismSame interface, different implementationsFlexibility, extensibilityPayment.process() → CardPayment, UPIPayment
AbstractionHide complexity, show essentialsReduce complexityDatabase interface hides SQL details

Design Patterns in LLD

Pattern Categories

┌─────────────────────────────────────────────┐
│           Design Patterns                    │
├──────────┬──────────────┬───────────────────┤
│Creational│ Structural   │ Behavioral        │
├──────────┼──────────────┼───────────────────┤
│Singleton │ Adapter      │ Observer          │
│Factory   │ Decorator    │ Strategy          │
│Builder   │ Proxy        │ Command           │
│Prototype │ Facade       │ Iterator          │
│          │ Composite    │ State             │
│          │              │ Template Method   │
└──────────┴──────────────┴───────────────────┘

When to Use Which Pattern

ProblemPatternExample
Need exactly one instanceSingletonDatabase connection pool
Create objects based on typeFactoryPayment processor creation
Complex object constructionBuilderBuilding a House object
Add behavior dynamicallyDecoratorAdding toppings to pizza
Convert incompatible interfacesAdapterOld API to new interface
Control access to objectProxyLazy loading, caching proxy
Notify dependents of changesObserverUI event handling
Algorithm varies at runtimeStrategySorting algorithms
Encapsulate a requestCommandUndo/redo operations
Object changes behavior by stateStateVending machine states

UML Class Diagrams

Relationships

Association:    A ──────── B  (A uses B)
Aggregation:    A ◇─────── B  (A has B, B can exist independently)
Composition:    A ◆─────── B  (A owns B, B cannot exist without A)
Inheritance:    A ───────▷ B  (A extends B)
Dependency:     A - - - - → B  (A depends on B temporarily)

Multiplicity

1     Exactly one
0..1  Zero or one
*     Many (zero or more)
1..1  One or more

Common LLD Interview Problems

ProblemKey ConceptsPatterns
Parking LotMultiple vehicle types, floorsStrategy, Factory
ElevatorState machine, schedulingState, Strategy, Observer
Library ManagementBook checkout, reservationsObserver, Strategy
ATMState machine, transactionsState, Command, Strategy
ChessBoard, pieces, movesStrategy, Factory
LinkedIn/TwitterUsers, posts, feedsObserver, Strategy
UberMatching, pricingStrategy, Observer
Food DeliveryOrders, restaurantsState, Observer
Movie TicketBooking, seatsStrategy, Observer
File SystemFiles, directoriesComposite, Iterator
Notification ServiceMultiple channelsStrategy, Observer, Decorator
LRU CacheCache evictionStrategy (eviction)
Key-Value StoreStorage, retrievalStrategy, Composite

LLD Interview Tips

  1. Clarify requirements first — “What are the main actors? What operations are needed?”
  2. Start with core classes — Identify nouns, then verbs
  3. Draw class diagrams — Always sketch relationships
  4. Apply patterns naturally — Don’t force patterns; use them where they fit
  5. Code the critical parts — Implement key methods, not boilerplate
  6. Discuss trade-offs — “I chose composition over inheritance because…”
  7. Handle edge cases — “What if the parking lot is full?”
  8. Think about extensibility — “How would we add a new vehicle type?”

How to Approach LLD Problems

Step-by-Step Process

1. Requirements (2 min)
   - Who are the actors?
   - What are the use cases?
   - What are the constraints?

2. Identify Classes (3 min)
   - Nouns → Classes
   - Verbs → Methods
   - Adjectives → Attributes

3. Define Relationships (3 min)
   - "has-a" → Composition/Aggregation
   - "is-a" → Inheritance
   - "uses" → Association/Dependency

4. Apply Design Patterns (3 min)
   - What pattern fits each requirement?
   - Justify your choice

5. Implement Code (15 min)
   - Write interfaces first
   - Implement core classes
   - Add key methods

6. Discuss (5 min)
   - SOLID principles
   - Extensibility
   - Edge cases

Cross-References


Each LLD problem page in this section follows a consistent structure: requirements, class diagrams (Mermaid), code examples, patterns used, SOLID principles, edge cases, and interview tips.