0
0
LLDsystem_design~12 mins

DRY (Don't Repeat Yourself) in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - DRY (Don't Repeat Yourself)

The DRY principle helps developers avoid repeating the same code or logic in multiple places. It encourages reusing components and centralizing logic to make systems easier to maintain and less error-prone.

Key requirements include modular design, single source of truth for logic, and easy updates without duplication.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  v
+-------------------+
|  Service Layer     |
|  +-------------+  |
|  | Auth Module |  |
|  +-------------+  |
|  +-------------+  |
|  | Data Module |  |
|  +-------------+  |
+-------------------+
  |
  v
Database
  |
  v
Cache
Components
User
user
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly across servers
API Gateway
api_gateway
Routes requests to appropriate services and handles authentication
Service Layer
service
Contains reusable modules implementing business logic following DRY
Auth Module
service_module
Handles authentication logic reused across services
Data Module
service_module
Manages data access logic reused across services
Database
database
Stores persistent data
Cache
cache
Stores frequently accessed data to reduce database load
Request Flow - 11 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayService Layer
Service LayerCache
CacheService Layer
Service LayerDatabase
DatabaseService Layer
Service LayerCache
Service LayerAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Cache
Impact:Cache misses increase, causing more database queries and higher latency
Mitigation:System continues working by querying database directly; cache can be rebuilt asynchronously
Architecture Quiz - 3 Questions
Test your understanding
Which component ensures that repeated business logic is centralized and reused?
ALoad Balancer
BCache
CService Layer
DAPI Gateway
Design Principle
This architecture demonstrates the DRY principle by centralizing reusable business logic in service modules. It avoids code duplication by having a single source of truth for authentication and data access logic, improving maintainability and reducing errors.