Bird
0
0
LLDsystem_design~12 mins

Chain of Responsibility pattern in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Chain of Responsibility pattern

The Chain of Responsibility pattern allows a request to pass through a chain of handlers. Each handler decides to process the request or pass it to the next handler. This design helps separate concerns and makes the system flexible to add or change handlers without modifying the client.

Architecture Diagram
User
  |
  v
Handler 1 ---> Handler 2 ---> Handler 3 ---> Null Handler
  |
Response
Components
User
client
Initiates the request to be handled
Handler 1
handler
First handler in the chain; processes or forwards request
Handler 2
handler
Second handler; processes or forwards request
Handler 3
handler
Third handler; processes or forwards request
Null Handler
handler
End of chain; handles unprocessed requests or returns default response
Request Flow - 8 Hops
UserHandler 1
Handler 1Handler 1
Handler 1Handler 2
Handler 2Handler 2
Handler 2Handler 3
Handler 3Handler 3
Handler 3Null Handler
Null HandlerUser
Failure Scenario
Component Fails:Handler 2
Impact:Requests that require Handler 2's processing are not handled and passed down the chain, possibly causing delays or incorrect handling.
Mitigation:Implement fallback logic in Handler 3 or Null Handler to handle requests if Handler 2 fails; monitor handler health and remove or restart failing handler.
Architecture Quiz - 3 Questions
Test your understanding
What happens if Handler 1 cannot process a request?
AIt forwards the request to Handler 2
BIt returns an error to the user
CIt processes the request anyway
DIt stops the request chain
Design Principle
The Chain of Responsibility pattern decouples sender and receiver by passing requests along a chain of handlers. This allows flexible and dynamic handling of requests without tight coupling, improving maintainability and scalability.