LLD vs HLD
Differences between Low and High Level Design
Overview
High-Level Design (HLD) and Low-Level Design (LLD) are two complementary phases of software design. Understanding the difference is crucial for architects and developers.
High-Level Design (HLD):
- System architecture overview
- Technology stack decisions
- Database design
- API contracts
- External integrations
- Non-functional requirements
Low-Level Design (LLD):
- Class and object design
- Method signatures
- Data structures
- Design patterns
- Detailed algorithms
- Code-level decisions
Key Concepts
HLD answers "What" - LLD answers "How"
HLD is for stakeholders - LLD is for developers
HLD uses architecture diagrams - LLD uses class diagrams
HLD decides technologies - LLD implements them
Both are essential for successful projects
Code Example
java
1// HLD Decision: Use REST API with JSON for user service
2
3// LLD Implementation:
4public class UserController {
5 private final UserService userService;
6
7 @GetMapping("/users/{id}")
8 public ResponseEntity<UserDTO> getUser(@PathVariable Long id) {
9 User user = userService.findById(id);
10 return ResponseEntity.ok(UserMapper.toDTO(user));
11 }
12}
13
14public class UserService {
15 private final UserRepository userRepository;
16 private final CacheService cacheService;
17
18 public User findById(Long id) {
19 // Check cache first
20 User cached = cacheService.get("user:" + id);
21 if (cached != null) return cached;
22
23 // Fetch from database
24 User user = userRepository.findById(id)
25 .orElseThrow(() -> new UserNotFoundException(id));
26
27 // Update cache
28 cacheService.put("user:" + id, user);
29 return user;
30 }
31}HLD decided to use REST API. LLD designs the actual classes, methods, caching strategy, and error handling.
Real-World Example
Building a ride-sharing app like Uber:
HLD decisions:
- Microservices architecture
- PostgreSQL for user data, MongoDB for ride history
- Kafka for real-time events
- Google Maps API for routing
LLD decisions:
- Ride class with attributes: id, rider, driver, status, route
- RideService with methods: requestRide(), assignDriver(), completeRide()
- Strategy pattern for pricing (surge, normal, promotional)
- Observer pattern for notifying riders and drivers