Design a Middleware Chain
Design a middleware pipeline for request processing. Include middleware interface with next-chain invocation, authentication, rate limiting, and logging middleware, chain assembly, and shared request context.
Suggested time: 45 minutes
Loading the workspace...
About this problem
A middleware chain is an elegant OOD problem because it combines the Chain of Responsibility pattern with decorator-style wrapping, immutable shared infrastructure, and per-request mutable state. Before designing classes, let's define exactly what the system must do.
What your design needs to cover
Define Middleware with Pre/Post-Processing
Chain Middlewares in Configurable Order
Short-Circuit: Halt Chain and Return Early
Shared Context Between Middlewares
Key challenges the editorial covers
Learn from other designs
Related problems
Design a Workflow Engine (hard)
Design a File System (hard)
Design a Spreadsheet (hard)