Skip to content

A comprehensive guide to Low-Level Design (LLD) in Java, covering design patterns, principles, and common interview questions.

Notifications You must be signed in to change notification settings

piyush7199/low-level-design-in-java

Repository files navigation

Low-Level Design (LLD) in Java πŸš€

Java Design Patterns Interview Ready

Welcome to the most comprehensive Low-Level Design resource for Java developers and interview candidates!

This repository contains 15 design patterns, 30 real-world system designs, and detailed explanations of OOP principles, SOLID, and software architecture best practices.

Perfect for:

  • 🎯 SDE Interview Preparation (Amazon, Google, Microsoft, etc.)
  • πŸ’Ό Software Engineers learning system design
  • πŸŽ“ Computer Science Students mastering OOP and design patterns
  • πŸ‘¨β€πŸ’» Developers building scalable, maintainable systems

πŸ“– What is Low-Level Design (LLD)?

Low-Level Design is the detailed design phase where you convert high-level architecture into:

  • βœ… Class diagrams and object relationships
  • βœ… Detailed code structures with proper abstractions
  • βœ… Design patterns for common problems
  • βœ… SOLID principles for maintainability

Why LLD matters in interviews:

  • 60% of system design interviews include LLD rounds
  • Tests your ability to write clean, extensible code
  • Demonstrates understanding of OOP and design patterns
  • Shows real-world problem-solving skills

🎯 Why This Repository?

For Interview Candidates:

  • βœ… Real interview questions from FAANG companies
  • βœ… Naive vs Improved solutions showing evolution
  • βœ… Pattern identification - learn when to use which pattern
  • βœ… Common pitfalls and how to avoid them

For Learning:

  • πŸ“˜ Comprehensive documentation for every concept
  • πŸ”Ή 15 Design Patterns with real-world use cases
  • πŸ›  30 Complete Systems from simple to complex
  • 🧩 Progressive difficulty - start simple, master complex
  • πŸ“Š UML diagrams for visual understanding

πŸ“‚ Repository Structure

low-level-design-in-java/
│── pom.xml
│── README.md
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/
β”‚   β”‚   β”‚   └── org/lld/
β”‚   β”‚   β”‚       β”œβ”€β”€ basic/
β”‚   β”‚   β”‚       β”œβ”€β”€ patterns/
β”‚   β”‚   β”‚       └── practice/
β”‚   β”‚   β”‚
β”‚   β”‚   └── resources/
β”‚   β”‚       └── docs/
β”‚   β”‚           └── basic/
β”‚   β”‚               └── solid.md
β”‚   β”‚
β”‚   └── test/java/

πŸ“˜ Documentation & Guides

Core Concepts

Interview Preparation


πŸ”Ή Design Patterns (Code)

πŸ”¨ Creational Design Patterns

# Pattern Name Description
1 Singleton Ensure a class has only one instance and provide a global point of access to it.
2 Builder Separates complex object construction from its representation.
3 Factory Creates objects without exposing the instantiation logic.
4 Prototype Create new objects by copying existing ones, reducing the cost of creation.
5 Abstract Factory Provides an interface for creating families of related or dependent objects without specifying their concrete classes.

🧱 Structural Design Patterns

# Pattern Name Description
1 Decorator Dynamically adds new behavior to objects at runtime.
2 Flyweight Reduces memory usage by sharing common parts of object state among objects.
3 Adapter Converts one interface into another expected by the client.
4 Proxy Provides a surrogate or placeholder to control access to another object.
5 Facade Provides a simplified interface to a complex subsystem.

🧠 Behavioural Design Patterns

# Pattern Name Description
1 Chain Of Responsibility Passes a request along a chain of handlers until one of them handles it.
2 Observer Defines a one-to-many dependency so that when one object changes state, all its dependents are notified and updated automatically.
3 Strategy Enables selecting an algorithm's behavior at runtime by encapsulating it within a class and making it interchangeable.
4 Command Encapsulates a request as an object, thereby allowing users to parameterize clients, delay execution, or queue and log operations.
5 State Allows an object to change its behavior when its internal state changes, appearing as if it changed its class.
6 Template Method Defines the skeleton of an algorithm, letting subclasses override specific steps.

πŸ›  Practice Problems

Each problem includes:

  • βœ… Naive Solution: Simple implementation showing common pitfalls
  • βœ… Improved Solution: Well-designed implementation using SOLID principles and design patterns
  • βœ… Comprehensive README: Problem statement, requirements, design considerations, and patterns used
# System Design Problem Key Patterns Used
1 Car Rental System Strategy, State, Factory
2 Parking Lot System Singleton, Strategy
3 Vending Machine State, Strategy
4 Snake And Ladder Factory, Strategy
5 Online Movie Booking System Singleton, Factory, Strategy
6 Online Hotel Booking System Strategy, Observer, Factory
7 ATM System State, Strategy, Command, Singleton
8 Library Management System Strategy, Observer, Repository, Facade
9 Elevator System State, Strategy, Observer, Command
10 Food Delivery System Strategy, State, Observer, Factory
11 Ride-Sharing System Strategy, State, Observer, Factory, Singleton
12 Queue Management System Singleton, Strategy, Observer, State
13 Cache Management System Strategy, Factory, Decorator, Builder
14 Rate Limiter Strategy, Factory, Builder
15 Matching Engine Strategy, Observer
16 Wallet / Ledger System Command, Observer, Builder
17 Pub/Sub System (Mini-Kafka) Observer, Strategy, Singleton
18 Task Scheduler Strategy, Command, Observer, Singleton
19 E-commerce Cart System Strategy, Decorator, Factory, Builder
20 Logger System Strategy, Observer, Factory, Chain of Responsibility
21 Notification System Strategy, Factory, Observer, Command
22 URL Shortener (TinyURL) Strategy, Factory, Repository
23 Chat Application Observer, Strategy, State, Repository
24 Leaderboard System Strategy, Factory, Observer
25 Calendar/Event Booking System Strategy, Factory, Observer, State, Repository
26 Expense Sharing System (Splitwise-like) Strategy, Factory, Graph Algorithm
27 Tic-Tac-Toe Game Strategy, State, Factory, Observer
28 Stock Trading System Strategy, State, Observer, Singleton, Factory
29 Social Media Feed System Strategy, Observer, Factory, Singleton
30 Online Auction System State, Observer, Strategy, Singleton

πŸš€ Getting Started

Prerequisites

  • Java 17 or higher
  • Maven (for building)
  • IDE (IntelliJ IDEA, Eclipse, or VS Code recommended)

Quick Start

  1. Clone the repository
git clone https://github.com/your-username/low-level-design-in-java.git
cd low-level-design-in-java
  1. Build the project
mvn clean install
  1. Run examples
# Run a specific pattern example
mvn exec:java -Dexec.mainClass="org.lld.patterns.creational.singleton.Main"

# Run a practice problem
mvn exec:java -Dexec.mainClass="org.lld.practice.design_parking_lot_system.improved_solution.Main"

Project Structure

src/main/java/org/lld/
β”œβ”€β”€ patterns/           # Design pattern implementations
β”‚   β”œβ”€β”€ creational/    # Factory, Singleton, Builder, etc.
β”‚   β”œβ”€β”€ structural/    # Adapter, Decorator, Proxy, etc.
β”‚   └── behavioural/   # Observer, Strategy, State, etc.
β”‚
β”œβ”€β”€ practice/          # Real-world system designs
β”‚   β”œβ”€β”€ design_parking_lot_system/
β”‚   β”œβ”€β”€ design_atm_system/
β”‚   └── ...
β”‚
└── resources/docs/    # Documentation
    └── basic/         # OOP, SOLID, UML guides

πŸ“š Learning Path

For Beginners (Start Here):

  1. Read OOP Concepts
  2. Understand SOLID Principles
  3. Start with simple patterns:
  4. Try simple problems:

For Intermediate (Building Skills):

  1. Study structural patterns (Decorator, Adapter, Flyweight)
  2. Master behavioral patterns (Observer, State, Command)
  3. Practice medium problems:

For Advanced (Interview Ready):

  1. Combine multiple patterns in complex systems
  2. Practice with real-world systems:
  3. Review INTERVIEW_GUIDE.md for tips

πŸ’‘ Interview Tips

Common LLD Interview Questions:

  • Design a Parking Lot System ⭐ Most Common
  • Design an Elevator System
  • Design a Library Management System
  • Design a Food Delivery App (Uber Eats)
  • Design a Ride-Sharing App (Uber)
  • Design a Hotel Booking System
  • Design a Movie Ticket Booking System
  • Design a Vending Machine
  • Design an ATM
  • Design a Car Rental System

What Interviewers Look For:

  1. βœ… Requirements gathering - Ask clarifying questions
  2. βœ… Core entities identification - Find main objects
  3. βœ… Relationships - Understand interactions
  4. βœ… Design patterns usage - Apply appropriately
  5. βœ… SOLID principles - Write clean code
  6. βœ… Extensibility - Design for future changes
  7. βœ… Trade-offs - Discuss pros/cons of your decisions

How to Use This Repo for Interviews:

  1. First: Try solving the problem yourself (30 mins)
  2. Then: Look at the naive solution to see common mistakes
  3. Finally: Study the improved solution to learn best practices
  4. Practice: Implement it from scratch without looking
  5. Explain: Practice explaining your design out loud

See INTERVIEW_GUIDE.md for detailed tips and strategies.


πŸ”₯ Key Design Patterns Quick Reference

Pattern Use When Example From Problems
Singleton Need exactly one instance ParkingLot, BankingService
Factory Object creation varies Vehicle types, User types
Builder Complex object construction Building Car with options
Strategy Algorithm varies at runtime Pricing, Matching, Payment
State Behavior changes with state Order lifecycle, Ride status
Observer One-to-many notifications Order updates, Ride tracking
Decorator Add responsibilities dynamically Coffee with add-ons
Adapter Interface compatibility Legacy system integration
Command Encapsulate requests Transaction operations
Repository Data access abstraction BookCatalog, MemberRegistry

πŸŽ“ Additional Resources


🀝 Contributing

We welcome contributions! Here's how:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-pattern)
  3. Commit your changes (git commit -am 'Add new pattern')
  4. Push to the branch (git push origin feature/new-pattern)
  5. Create a Pull Request

Contribution Ideas:

  • πŸ†• Add new design patterns (Proxy, Bridge, Composite)
  • πŸ“ Improve documentation and examples
  • πŸ› Fix bugs or improve existing solutions
  • 🎨 Add UML diagrams
  • βœ… Add unit tests
  • 🌍 Add translations

πŸ“ˆ Repository Stats

  • Design Patterns: 15 implemented
  • Practice Problems: 30 complete systems
  • Code Examples: 350+ files
  • Lines of Code: 15000+
  • Documentation: Comprehensive READMEs for each topic

⭐ Show Your Support

If this repository helped you:

  • ⭐ Star the repository
  • πŸ”€ Fork it for your own learning
  • πŸ“’ Share with friends and colleagues
  • πŸ’¬ Feedback - open an issue with suggestions

πŸ“§ Contact & Support


πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgements

Created with ❀️ for the developer community.

Special thanks to:

  • Gang of Four for Design Patterns
  • Robert Martin for SOLID principles
  • All contributors and supporters

Remember: Good design is not about following rules blindly, but understanding trade-offs and making informed decisions!

Happy Learning and Good Luck with your interviews! πŸš€

About

A comprehensive guide to Low-Level Design (LLD) in Java, covering design patterns, principles, and common interview questions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages