APIsIntermediate

What belongs in an API gateway?

“What should an API gateway do, what must it never do, and how do you stop it from becoming the new monolith?”

What this tests

  • Edge concerns vs business logic
  • Recognising the "gateway becomes the monolith" failure
  • BFF as the sanctioned place for client-specific aggregation
  • High availability of the gateway itself

Answers by level

Read the beginner answer first and notice what is missing.

A gateway owns edge concerns that are the same for every service: TLS termination, authentication (validate the token, forward identity), rate limiting per client, routing, request logging and trace-id injection, basic transformation (headers, protocol translation such as REST to gRPC), and coarse-grained caching. These are cross-cutting, change rarely, and benefit from one enforcement point.

It must not own business logic or orchestration: no "if the customer is premium, call Pricing then Discounts". As soon as it aggregates data with rules, every feature touches the gateway, every team deploys it, and it becomes a shared bottleneck with a p99 that grows with every rule — the gateway becomes the monolith. Client-specific aggregation belongs in a Backend-for-Frontend owned by the client team, which can compose service calls for that screen without becoming a shared chokepoint.

It is a single point of failure by construction, so it runs as a stateless fleet behind DNS or anycast with health checks, with its configuration versioned and deployed like code, and with its own timeouts and breakers per upstream so a slow service does not exhaust gateway connections.

Green flags · Red flags

Strong green flag · Proposes declarative, pull-request-driven gateway config so no team needs to write gateway code.
Green flags
  • Lists edge concerns precisely: TLS, authn, rate limit, routing, logging, trace ids
  • Refuses business logic and aggregation in the gateway
  • Names the BFF as the place for client-specific composition
  • Addresses the gateway as a SPOF with a stateless fleet and per-upstream timeouts
  • Uses ownership and deploy frequency as the health signal
Red flags
  • "The gateway is the natural place for shared business logic since everything goes through it."
  • Puts data aggregation with rules in the gateway
  • Ignores gateway availability
  • Cannot distinguish a BFF from a gateway

Follow-up questions

F1
Mobile needs a combined user+orders response. Where does that go?
F2
What happens if a slow upstream has no gateway-side timeout?
F3
How do you make the gateway highly available?

Scenario

The gateway repo has 40 contributors, 200 routes, 30 "aggregation handlers" and a p99 that doubled this year. Every product feature includes a gateway pull request. Propose a structure that returns the gateway to edge concerns and say where each aggregation handler goes.

Learn this topic