Build a Composable Request Middleware Chain for an RPC Server

Last updated: November 29, 2026

Quick Overview

Design a middleware system where cross-cutting concerns such as logging, authentication, and error handling wrap a request handler in a configurable order, and any middleware can short-circuit the request.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


Design a middleware system where cross-cutting concerns such as logging, authentication, and error handling wrap a request handler in a configurable order, and any middleware can short-circuit the request.

Google's RPC frameworks expose interceptors for auth, tracing, deadlines, and monitoring, so engineers reason about wrapper order daily. This screen checks function composition, the chain of responsibility pattern, and whether the candidate understands how order changes behavior.

What the Interviewer Expects
  • Represents middleware as a function of request and next handler
  • Composes the chain so the first listed is the outermost wrapper
  • Allows short-circuiting without calling next
  • Shows how order matters, e.g. error handling outside auth
  • Avoids mutating the shared request object
Key Topics to Cover
chain of responsibility
decorator pattern
function composition
interceptors
short-circuit
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you add per-request deadlines that propagate to downstream calls?
  • How would you support async handlers?
  • How would you make a middleware apply only to some routes?
  • How would you test middleware in isolation?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • A middleware receives (request, next) and returns a response.
  • chain(middlewares, handler) returns a single handler.
  • Middleware may modify the request, inspect the response, or return early. ...
High-Level Design

Build the chain from the inside out: the innermost is the real handler, and each middleware is wrapped around the next one. With the list [logging, error, auth], a request enters logging, then error...


Submit Your Answer
Markdown supported