An API Gateway Enforces Authentication, Rate Limits and Usage Analytics Before Requests Reach the Backend

In progress Networking AppSec

An API gateway is a reverse proxy that understands APIs: every consumer calls the gateway, and the gateway decides whether, how fast and where a request goes before any backend sees it. Concerns that each service would otherwise implement on its own, such as checking keys or tokens, limiting traffic and measuring usage, are then done once, in one place, with one policy.

What Moves from the Services to the Gateway

Concern Done by the gateway
Authentication checks API keys or OAuth 2.0 tokens; unauthenticated requests never reach the backend
Traffic management rate limiting (a request quota per consumer and period) and throttling (smoothing spikes) protect the backend from overload
Analytics per-consumer usage, latency and error rates, measured at a single point
Developer access a portal where developers register, get keys and choose a plan, so that an internal API can become a product

Google Cloud's Apigee is one product of this kind. Cloud providers and open-source proxies offer others, with the same idea: the gateway works at layer 7, on requests, paths and headers, not on connections (see Layer 4 Load Balancers Route Connections, Layer 7 Load Balancers Route Requests).

The Backend Must Trust Only the Gateway

The gateway protects nothing if a backend can also be reached directly, because a client then skips authentication and limits by calling the service's own address. The backend should accept traffic only from the gateway, and treat the identity the gateway passes on (a header or a verified token) as authoritative only on that path.

When a Gateway Is More Than You Need

For one API with one consumer, a gateway adds a hop, a component to run and a single point of failure in front of everything. It pays off when several services or many consumers need the same policy, or when usage has to be measured per consumer, for quotas or billing.

References

Review cards

Flashcard Why should the backend trust only the gateway?

Because if the backend can be reached directly, a client can bypass authentication and rate limits by calling the service's own address.

Flashcard At an API gateway, how does rate limiting differ from throttling?

Rate limiting caps how many requests a consumer may make per period. Throttling smooths spikes by slowing requests down, so that the backend isn't overloaded.

Flashcard Why does per-IP rate limiting at a gateway behind a load balancer throttle everyone or no one?

Every request arrives from the load balancer's IP. The gateway must read the client address from forwarded headers set by a proxy it trusts.

Flashcard When is an API gateway more than you need?

With one API and one consumer: it adds a hop, a component to run and a single point of failure. It pays off when many services or consumers share a policy, or usage must be metered.