liveBook · Manning

API gateway

As explained in Grokking Software Architecture

An API gateway is a centralized edge server that provides a single entry point for external clients and routes requests to internal services while enforcing shared perimeter concerns.

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

How Grokking Software Architecture covers it

How deep it goes
Defines gateway responsibilities and illustrates aggregation with asynchronous HTTP calls, without detailing gateway deployment or configuration.
Examples
Uses excessive login attempts, an orders request, and a three-service page aggregator to illustrate gateway responsibilities and tradeoffs.
What you can do after
Evaluate how a gateway supports perimeter security and where distributed aggregation adds complexity.
How it connects
Connects the gateway to identity providers, defense in depth, Zero Trust, and microservices.

Also explained in

Compare how 10 books explain API gateway →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.