LLD vs HLD
Low-Level Design (LLD) and High-Level Design (HLD) are complementary phases of software design that operate at different levels of abstraction.
High-Level Design (HLD)
HLD focuses on the big picture — how major components of the system interact:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Client │───▶│ API Server │───▶│ Database │
│ (Browser) │ │ (REST API) │ │ (Postgres) │
└─────────────┘ └─────────────┘ └─────────────┘
│ │
│ ┌─────────────┐ │
└─────────▶│ Cache │◀───────────┘
│ (Redis) │
└─────────────┘
HLD answers:
- What services exist?
- How do they communicate?
- What databases and storage are used?
- What are the scalability strategies?
Low-Level Design (LLD)
LLD dives into individual components — how specific classes, methods, and data structures are designed:
┌────────────────────────────┐
│ OrderService │
├────────────────────────────┤
│ - orderRepository: OrderRepo │
│ - paymentService: PaymentSvc │
│ - inventoryService: InventorySvc │
├────────────────────────────┤
│ + createOrder(cart: Cart): Order │
│ + cancelOrder(id: String): void │
│ + getOrder(id: String): Order │
└────────────────────────────┘
▲ ▲ ▲
│ │ │
┌────┘ ┌────┘ ┌────┘
│ │ │
┌───┴───┐ ┌───┴───┐ ┌───┴───┐
│Order │ │Payment│ │Inven- │
│Repo │ │Service│ │tory │
└───────┘ └───────┘ └───────┘
LLD answers:
- What classes exist?
- What are the method signatures?
- How is data structured internally?
- What design patterns are used?
- How do objects collaborate?
The Design Spectrum
HLD ◀──────────────────────────────▶ LLD
Architecture Component Class/Module
Decisions Boundaries Design
"What services "How does "What methods
exist?" service A does Order
talk to B?" Service have?"
When LLD is Needed
| Situation | Need for LLD |
|---|---|
| New feature development | High — design classes before coding |
| Bug fix in existing code | Low — understand existing LLD |
| Refactoring | Medium — redesign class boundaries |
| Code review | Medium — verify LLD principles |
| Interview design round | High — demonstrate design thinking |
LLD Outputs
- Class diagrams: Show classes, attributes, methods, and relationships
- Sequence diagrams: Show object interactions over time
- Interface definitions: Define contracts between components
- Data structure choices: Select appropriate collections and algorithms
- Design pattern applications: Identify where patterns solve recurring problems
Class Design
Class design is the core of LLD. It transforms abstract requirements into concrete, implementable structures.
The Class Design Process
Requirements
│
▼
Identify Entities ──▶ Define Responsibilities
│ │
▼ ▼
Design Interfaces ◀── Determine Relationships
│
▼
Choose Patterns
│
▼
Define Attributes & Methods
Step 1: Identify Nouns as Candidate Classes
From a requirement like "Users can browse books, add them to cart, and checkout":
| Noun | Potential Class |
|---|---|
| User | User |
| Book | Book |
| Cart | ShoppingCart |
| Checkout | CheckoutService |
| Order | Order |
| Payment | PaymentService |
Step 2: Assign Responsibilities
User
├── Responsibility: Authentication, Profile Management
├── Attributes: id, name, email, passwordHash
└── Methods: login(), logout(), updateProfile()
ShoppingCart
├── Responsibility: Track selected items
├── Attributes: userId, items[], totalAmount
└── Methods: addItem(), removeItem(), checkout()
Order
├── Responsibility: Record purchase transaction
├── Attributes: id, userId, items[], total, status
└── Methods: confirm(), cancel(), getStatus()
Step 3: Define Relationships
┌──────────┐ 1 * ┌──────────┐
│ User │─────────▶│ Order │
└──────────┘ └──────────┘
│ 1 │ *
│ │
▼ * ▼ *
┌──────────────┐ ┌──────────┐
│ ShoppingCart │ │OrderItem │
└──────────────┘ └──────────┘
│ *
│
▼ 1
┌──────────┐
│ Book │
└──────────┘
SOLID Principles in Class Design
- Single Responsibility: Each class has one reason to change
- Open-Closed: Open for extension, closed for modification
- Liskov Substitution: Subtypes must be substitutable for base types
- Interface Segregation: Prefer specific interfaces over general ones
- Dependency Inversion: Depend on abstractions, not concrete classes
Common Anti-Patterns
- God Class: One class doing everything
- Anemic Domain Model: Classes with only getters/setters, logic elsewhere
- Circular Dependencies: A depends on B, B depends on A
- Feature Envy: Method uses another class's data more than its own
UML Overview
Unified Modeling Language (UML) provides standardized visual notations for expressing LLD designs.
UML Diagram Categories
UML Diagrams
├── Structural Diagrams (what the system IS)
│ ├── Class Diagram
│ ├── Object Diagram
│ ├── Component Diagram
│ ├── Deployment Diagram
│ └── Package Diagram
│
└── Behavioral Diagrams (what the system DOES)
├── Sequence Diagram
├── Activity Diagram
├── State Machine Diagram
└── Use Case Diagram
Class Diagram Notation
┌──────────────────────────┐
│ «interface» │
│ PaymentMethod │
├──────────────────────────┤
│ │
├──────────────────────────┤
│ + pay(amount: double): boolean │
│ + refund(amount: double): boolean │
└──────────────────────────┘
△
│ implements
┌───────┴────────┐
│ │
┌───┴────┐ ┌─────┴──────┐
│CreditCard│ │ PayPal │
├────────┤ ├────────────┤
│-cardNum │ │-email │
│-expiry │ │-token │
├────────┤ ├────────────┤
│+pay() │ │+pay() │
│+refund()│ │+refund() │
└────────┘ └────────────┘
Key UML Symbols
| Symbol | Meaning |
|---|---|
+ |
Public |
- |
Private |
# |
Protected |
~ |
Package |
underline |
Static |
*itabc* |
Abstract/Italic |
«» |
Stereotype |
◆ |
Composition (strong ownership) |
◇ |
Aggregation (weak ownership) |
──▶ |
Association |
- - -▶ |
Dependency |
△ |
Inheritance |
Multiplicity Notation
┌────────┐ 1 0..* ┌────────┐
│ Teacher│────────────▶│ Student│
└────────┘ └────────┘
1 = exactly one
0..* = zero or more
1..* = one or more
0..1 = zero or one
5 = exactly five
Choosing the Right Diagram
| Need | Use |
|---|---|
| Show class structure | Class Diagram |
| Show object interactions | Sequence Diagram |
| Show state transitions | State Machine Diagram |
| Show workflow | Activity Diagram |
| Show system components | Component Diagram |
| Show deployment topology | Deployment Diagram |
Practice Problems
Design a scalable What is LLD? system. Cover high-level architecture, data model, and API design.
Solution
// Complete system design:
// - Functional + Non-functional requirements
// - Capacity estimation
// - Data model (SQL/NoSQL choice)
// - API endpoints
// - Component architecture
// - Scaling strategy
// - Monitoring & reliabilityHow would you scale What is LLD? to handle 10x the current load? Identify bottlenecks and solutions.
Solution
// Scaling approach:
// 1. Load balancing
// 2. Database sharding/replication
// 3. Cache layer (Redis)
// 4. CDN for static assets
// 5. Async processing (queues)
// 6. Microservices decompositionAnalyze potential failure modes for What is LLD? and design mitigation strategies.
Solution
// Failure mitigation:
// 1. Redundancy (multi-AZ)
// 2. Circuit breakers
// 3. Retry with backoff
// 4. Dead letter queues
// 5. Health checks
// 6. Graceful degradationQuiz
1. What is the primary difference between HLD and LLD?
2. Which UML diagram is most useful for showing how classes interact over time?
3. In UML, what does the diamond symbol (◆) represent?
4. What is a key output of Low-Level Design?
5. Which of these is NOT a UML structural diagram?
Flashcards
Question
What is Low-Level Design (LLD)?
Click to reveal answer
Answer
The phase of software design that focuses on detailed class design, method signatures, data structures, and design patterns within individual components.
Question
How does LLD differ from HLD?
Click to reveal answer
Answer
HLD defines system-wide architecture (services, databases, communication patterns). LLD defines class-level details (attributes, methods, relationships, design patterns).
Question
What are the main UML diagram types?
Click to reveal answer
Answer
Structural: Class, Object, Component, Deployment, Package. Behavioral: Sequence, Activity, State Machine, Use Case.
Question
What does multiplicity 0..* mean in UML?
Click to reveal answer
Answer
Zero or more instances. For example, a User can have zero or many Orders.
Question
What are the key outputs of LLD?
Click to reveal answer
Answer
Class diagrams, sequence diagrams, interface definitions, data structure choices, and design pattern applications.
Revision Notes
Key Takeaways
- 1.LLD focuses on class-level details while HLD focuses on system-wide architecture
- 2.LLD produces class diagrams, sequence diagrams, and interface definitions
- 3.UML provides standardized visual notations for LLD designs
- 4.SOLID principles guide good class design
- 5.LLD bridges the gap between requirements and implementation
Interview Tips
- •Start with class diagrams showing core entities and their relationships
- •Use sequence diagrams to illustrate key workflows
- •Discuss design patterns when they naturally fit the problem
- •Always consider SOLID principles when proposing class designs
Cheat Sheet
What is LLD - Cheat Sheet
LLD vs HLD:
| Aspect | HLD | LLD |
|---|---|---|
| Scope | System-wide | Component/class-level |
| Focus | Architecture, services | Classes, methods, patterns |
| Output | Architecture diagrams | Class/sequence diagrams |
UML Diagram Types:
- Structural: Class, Component, Deployment
- Behavioral: Sequence, Activity, State Machine
Class Diagram Symbols:
+Public,-Private,#Protected◆Composition,◇Aggregation△Inheritance,--▶Dependency
LLD Process:
- Identify nouns → candidate classes
- Assign responsibilities
- Define relationships
- Apply SOLID principles
- Choose design patterns