Chain of Responsibility: Pass a request along a chain of handlers, each deciding to process it or pass it to the next handler in the chain. In the Chain of Responsibility pattern, a request passes through a series of handlers. Each handler either deals with it or passes it on to the next one.
Frequently asked questions about Chain of Responsibility
How is Chain of Responsibility used in practice?
HTTP middleware is the best-known example. A request passes through authentication, rate limiting, locale detection and so on. Any handler can stop the chain, for example by returning a 401, or let the request continue to the controller.
What should you keep in mind with Chain of Responsibility?
The pattern keeps each step small and independent, and you can add or reorder steps without touching the others. The risk is that the order matters and is easy to get wrong. If logging runs before authentication, you log requests you later reject. Keep the chain short enough that someone can read it top to bottom, and document why the order is what it is.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.
'Cloud design patterns for distributed systems architecture covering 42 industry-standard patterns across reliability, performance, messaging, security, and deployment categories. Use when designing, reviewing, or implementing distributed system architectures.'