Apply Now Apply Now Apply Now
header_logo
Post thumbnail
SOFTWARE DEVELOPMENT

Chain of Responsibility Design Pattern: A Complete Beginner’s Guide

By Vaishali

Modern applications often process requests through multiple layers based on conditions or priorities. For example, a support ticket may move from a chatbot to an executive and then to a manager. Hardcoding such workflows creates tightly coupled systems that are difficult to maintain. The Chain of Responsibility Design Pattern solves this by passing requests through multiple handlers dynamically while keeping components loosely connected.

In this blog, you will learn what the Chain of Responsibility Design Pattern is, how it works, its structure, advantages, disadvantages, implementation examples, and real-world applications.

Quick Answer:

The Chain of Responsibility Design Pattern is a behavioral design pattern that allows multiple objects to handle a request sequentially without tightly coupling the sender to a specific receiver. The request moves through a chain of handlers until one object processes it. This pattern is widely used in customer support systems, approval workflows, logging systems, middleware pipelines, and authentication mechanisms because it improves scalability and maintainability.

Table of contents


  1. What is a Chain of Responsibility Design Pattern?
  2. Core Concept: The “Bucket Brigade” Approach
  3. Key Components of Chain of Responsibility
    • Handler Interface
    • Concrete Handlers
    • Client
  4. How the Chain of Responsibility Pattern Works
    • Internal Workflow
    • Technical Architecture
    • Request Delegation Mechanism
    • Key Technical Characteristics
    • Common Processing Strategies
  5. Advantages of Chain of Responsibility Design Pattern
  6. Disadvantages of Chain of Responsibility Design Pattern
  7. Real-World Examples of Chain of Responsibility Design Pattern
    • ATM Cash Withdrawal Processing
    • Spring Security Authentication Pipeline
    • Customer Support Ticket Escalation System
  8. Conclusion
  9. FAQs
    • How is the Chain of Responsibility pattern different from direct method calls?
    • Can multiple handlers process the same request in the Chain of Responsibility pattern?

What is a Chain of Responsibility Design Pattern?

The Chain of Responsibility Design Pattern is a behavioral design pattern that creates a sequential request-processing pipeline where multiple handlers are linked dynamically. Instead of tightly coupling the sender to a single receiver, the request moves through independent handlers until one processes it or stops the flow. Each handler contains specific processing logic and a reference to the next handler, enabling delegated request propagation. This pattern supports loose coupling, modular workflows, runtime chain configuration, and scalable processing pipelines.

Core Concept: The “Bucket Brigade” Approach

The Chain of Responsibility pattern works like a sequential request-processing pipeline where a request travels through multiple handlers until one successfully processes it. Each handler acts as an independent processing unit responsible for evaluating, handling, or forwarding the request.

A simple way to understand this is through a technical support escalation system:

  • Level 1 (Bot): Handles basic FAQs and predefined issues
  • Level 2 (Junior Executive): Performs intermediate troubleshooting and account-level checks
  • Level 3 (Senior Engineer): Resolves highly technical or critical system-level problems

If one level cannot resolve the issue, the request is automatically delegated to the next handler in the chain.

The user sending the request does not need to know which specific component or person will ultimately solve the issue. The request is simply submitted to the first handler, and the chain manages the delegation process internally.

This creates:

  • Loose coupling between sender and receiver
  • Flexible request-routing logic
  • Scalable processing pipelines
  • Cleaner separation of responsibilities

The same architecture is widely used in:

  • Middleware pipelines
  • API gateways
  • Authentication filters
  • Logging frameworks
  • Approval workflows
  • Event-processing systems

Key Components of Chain of Responsibility

The Chain of Responsibility pattern typically consists of three primary actors:

1. Handler Interface

The Handler defines the common contract for all processing objects in the chain.

It usually contains:

  • A method for processing requests
  • A reference or setter for the next handler

This creates a standardized communication structure between handlers.

Example responsibilities:

  • Validate request
  • Process request
  • Forward request to successor

2. Concrete Handlers

Concrete Handlers are the actual processing units that implement business logic.

Each handler:

  • Checks whether it can process the request
  • Executes its logic if applicable
  • Otherwise delegates the request to the next handler

Every handler focuses on a single responsibility, improving modularity and maintainability.

Examples:

  • AuthenticationHandler
  • AuthorizationHandler
  • ValidationHandler
  • LoggingHandler

3. Client

The Client is responsible for:

  • Creating the handlers
  • Linking them together into a chain
  • Sending the initial request

The client only interacts with the first handler and remains completely unaware of how the request flows internally through the system. This abstraction significantly reduces system dependencies and improves architectural flexibility.

Go beyond just learning software design patterns and start building scalable, maintainable applications with structured expertise. Join HCL GUVI’s AI-Powered Software Development Course to learn through live online classes led by industry experts. Master in-demand skills like system design, backend development, APIs, object-oriented programming, and scalable software architectures while working on real-world projects. Get 1:1 doubt support and access placement assistance with 1000+ hiring partners.

MDN

How the Chain of Responsibility Pattern Works

The Chain of Responsibility pattern works by organizing multiple handler objects into a sequential processing pipeline. Instead of directly assigning a request to one specific object, the request is passed through a chain where each handler decides whether it can process the request or forward it to the next handler.

Each handler contains two primary responsibilities:

  • Processing the request if it matches its handling criteria
  • Passing the request to the next handler if it cannot process it

This creates a decoupled request-processing mechanism where the sender does not need to know which object will ultimately handle the request.

Internal Workflow

The pattern typically follows this execution flow:

  1. The client sends a request to the first handler in the chain.
  2. The handler evaluates the request conditions.
  3. If the handler can process the request, execution stops.
  4. If the handler cannot process it, the request is delegated to the next handler.
  5. The process continues until:
    • A handler processes the request
    • Or the chain reaches its end

This structure forms a dynamic request propagation system that supports flexible runtime behavior.

Technical Architecture

The pattern usually contains:

  • A common handler interface or abstract class
  • Multiple concrete handlers implementing processing logic
  • A reference to the next handler in the chain
  • A client that initiates the request flow

Each handler maintains a reference to its successor, creating a linked processing structure similar to a pipeline or recursive delegation mechanism.

Request Delegation Mechanism

Handlers typically use conditional logic to determine responsibility.

Example flow:

Client Request

      ↓

Authentication Handler

      ↓

Authorization Handler

      ↓

Validation Handler

      ↓

Business Logic Handler

If authentication succeeds, the request moves to authorization. If authorization succeeds, validation begins, and so on.

Key Technical Characteristics

  • Loose Coupling

The sender remains independent from concrete receivers because it only communicates with the first handler.

  • Dynamic Chain Composition

Handlers can be rearranged, added, or removed at runtime without affecting the client code.

  • Single Responsibility

Each handler focuses on one specific processing responsibility, improving maintainability and modularity.

  • Sequential Processing

The request flows linearly through handlers until processing completes.

Common Processing Strategies

The Chain of Responsibility pattern generally supports two handling models:

  • Single Handler Processing

Only one handler processes the request, and propagation stops afterward.

  • Multi-Handler Processing

Multiple handlers process the same request sequentially before completion.

This flexibility makes the pattern highly suitable for middleware architectures, event processing systems, logging frameworks, and security pipelines.

Advantages of Chain of Responsibility Design Pattern

  • Reduces Tight Coupling

The sender only forwards the request without knowing which object will process it. This minimizes direct dependencies between components and improves system flexibility.

  • Supports Single Responsibility Principle

Each handler focuses on one dedicated responsibility such as validation, authentication, logging, or approval processing, resulting in cleaner and more maintainable code.

  • Simplifies Complex Workflows

Large request-processing pipelines become easier to organize because responsibilities are distributed across multiple independent handlers.

  • Enables Dynamic Workflow Configuration

Applications can configure request-processing chains dynamically at runtime based on business rules or user roles.

  • Improves Code Maintainability

Independent handlers reduce code duplication and allow developers to update individual processing logic without impacting the entire system.

  • Encourages Modular Architecture

Handlers act as reusable modules that can be integrated into different workflows across the application.

  • Supports Open/Closed Principle

The system remains open for extension but closed for modification because new handlers can be introduced without changing existing classes.

  • Improves Request Processing Control

The chain structure provides better control over how requests move through validations, filters, or approval stages.

  • Promotes Reusability

The same handlers can be reused across multiple processing pipelines, reducing redundant implementation efforts.

  • Works Well with Middleware Architectures

The pattern integrates naturally with middleware systems used in APIs, web frameworks, authentication pipelines, and event-driven architectures.

Disadvantages of Chain of Responsibility Design Pattern

  • Requests may remain unhandled if no handler processes them
  • Debugging long chains can become difficult
  • Performance overhead may increase with large chains
  • Incorrect handler order can break workflows
  • Request flow becomes harder to trace in complex systems
  • Too many handlers can reduce readability
  • Chain configuration may require additional management logic

Real-World Examples of Chain of Responsibility Design Pattern

1. ATM Cash Withdrawal Processing

In ATM systems, withdrawal requests pass through multiple validation handlers before money is dispensed. The system may sequentially check:

  • Card validation
  • PIN authentication
  • Account balance verification
  • Daily withdrawal limit
  • Fraud detection rules

Each handler processes one responsibility and forwards the request to the next validation stage.

2. Spring Security Authentication Pipeline

In Spring Security, HTTP requests move through a chain of security filters where different handlers process:

  • JWT token validation
  • Session authentication
  • CSRF protection
  • Role-based authorization
  • Request logging

Each filter decides whether the request should continue through the security chain or be blocked.

3. Customer Support Ticket Escalation System

In enterprise support systems, tickets move through multiple support levels:

  • Chatbot handles basic FAQs
  • Support executive resolves common issues
  • Technical specialist handles advanced problems
  • Manager handles critical escalations

If one level cannot resolve the issue, the request automatically moves to the next handler in the chain.

Conclusion

The Chain of Responsibility Design Pattern helps applications process requests through flexible and scalable handler pipelines without tightly coupling senders to receivers. By distributing responsibilities across independent handlers, it improves modularity, maintainability, and workflow management. From authentication filters and middleware systems to approval workflows and support escalations, this pattern plays a critical role in building clean, extensible, and scalable modern software architectures.

FAQs

How is the Chain of Responsibility pattern different from direct method calls?

Direct method calls tightly connect the sender to a specific receiver, while the Chain of Responsibility pattern routes requests through multiple independent handlers dynamically.

MDN

Can multiple handlers process the same request in the Chain of Responsibility pattern?

Yes. Depending on implementation, multiple handlers can process a request sequentially before the workflow completes.

Success Stories

Did you enjoy this article?

Schedule 1:1 free counselling

Similar Articles

Loading...
Get in Touch
Chat on Whatsapp
Request Callback
Share logo Copy link
Table of contents Table of contents
Table of contents Articles
Close button

  1. What is a Chain of Responsibility Design Pattern?
  2. Core Concept: The “Bucket Brigade” Approach
  3. Key Components of Chain of Responsibility
    • Handler Interface
    • Concrete Handlers
    • Client
  4. How the Chain of Responsibility Pattern Works
    • Internal Workflow
    • Technical Architecture
    • Request Delegation Mechanism
    • Key Technical Characteristics
    • Common Processing Strategies
  5. Advantages of Chain of Responsibility Design Pattern
  6. Disadvantages of Chain of Responsibility Design Pattern
  7. Real-World Examples of Chain of Responsibility Design Pattern
    • ATM Cash Withdrawal Processing
    • Spring Security Authentication Pipeline
    • Customer Support Ticket Escalation System
  8. Conclusion
  9. FAQs
    • How is the Chain of Responsibility pattern different from direct method calls?
    • Can multiple handlers process the same request in the Chain of Responsibility pattern?