Imagine a castle with a separate outside door for every room. Each door needs its own guard. An API gateway replaces those doors with a fortified main gate: a centralized edge server or server cluster that receives external client requests and routes them to internal services. section 11.3.1
Clients use the gateway rather than calling microservices directly. The gateway moves shared perimeter work out of business logic, so each service need not build its own public-facing defenses. section 11.3 section 11.3.1
The gateway can handle several jobs at the entrance:
- Rate limiting: drop excessive traffic, such as 500 login attempts from one IP address in a minute, before it reaches the authentication service. section 11.3.1
- TLS termination: decrypt incoming HTTPS traffic at the gateway. section 11.3.1
- Request routing: send a request such as GET /orders/123 to the appropriate service. section 11.3.1
- Initial authentication: check the user's token before admitting the request. An identity provider issues the token; the gateway checks it. section 11.3.1 section 11.3.2
Figure 11.3 The IdP issues the "Royal Seal" (JWT), which the API Gateway verifies to ensure the user is who they claim to be.
See how an identity provider issues a token for the gateway to verify. section 11.3.2
A strong front gate is not the whole security plan. Defense in depth adds other protections, while Zero Trust requires internal requests to be authenticated and authorized rather than trusted merely because they passed the perimeter. Rate limiting and a web application firewall at the gateway can also help drop denial-of-service traffic before it reaches services. section 11.10 section 11.6
When a gateway aggregates
A page may need a post, its author, and its comments from three different services. An aggregator can collect those pieces, but it must deal with network calls, separate HTTP status codes, and partial failures. That extra complexity is a tradeoff to weigh against the benefits of independently scaling services. section 12.7.2









