Topic 041 / Core
API gateway
Chapter 3.8 · Edge Infrastructure
What and why
A reverse proxy (→ 29) routes requests and terminates TLS, but a system with many client types and many backend services needs more at that single entry point: consistent authentication, rate limiting, and request shaping without every service reimplementing it. An API gateway is a specialized reverse proxy that adds authentication, rate limiting (→ 96), routing and response aggregation across services, protocol translation, and per-client policy enforcement at one front door. Builds on: → 29.
Diagram
plain reverse proxy: client ──► proxy ──► routes only ──► backend
API gateway: client ──► gateway {authenticate, rate-limit (→96),
route, aggregate} ──► service A / B / C
How it works
- Every external request enters through the gateway rather than hitting services directly.
- The gateway authenticates the request, or forwards identity it already validated (→ 39), before any service sees it.
- The gateway enforces rate limits (→ 96) per client.
- The gateway routes to the correct backend service, and may aggregate several service calls into one response for the client.
- The gateway may translate protocols — for example, a public REST call fanning out to internal gRPC calls (→ 33).
- Because every request passes through it, the gateway itself must run as more than one instance behind its own load balancing (→ 92); a single instance is a hidden single point of failure.
Practical example
(illustrative). A mobile client calls one gateway endpoint
GET /home-feed, which the gateway resolves by calling three internal services (user,
feed, notifications) and assembling one combined response — the client never knows three
services were involved.
When to use it
- Use when: there's more than one backend service and more than one client type needing consistent cross-cutting policy — auth, rate limits, routing — applied once instead of inside every service.
- Avoid when: there is exactly one service and one client type — a plain reverse proxy (→ 29) does the job with less to operate and no risk of business logic creeping into the gateway.
- Failure scenarios: the gateway becomes a single point of failure if under-provisioned or run as one instance; business logic that belongs in a service quietly accumulates in gateway configuration, coupling every service's behavior to one shared component.
- Simpler alternative: a plain reverse proxy, or no proxy at all, for a single-service system.
Practice
(pattern kind — implement minimal; 20–30 min, no lab services). Configure a gateway (or a small custom one) in front of two backend services, adding one cross-cutting policy — a shared rate limit or a shared auth check — that neither service implements itself. Verify both services are protected by that one gateway-level check. Done when a request violating the policy is blocked at the gateway before reaching either backend.
Key takeaway
An API gateway centralizes cross-cutting request policy at one front door, at the cost of becoming a component every request now depends on. Done when you can: name one policy that belongs at the gateway and one that belongs inside a service, and say why. Used next in → 96 (rate limiting detail); → 148 (BFF, a client-shaped alternative); Project 4 (checklist: no single gateway instance, topic 92; auth forwarding, topic 39).
References
None — this topic makes no external claims.
Source directory