# API Gateway

A managed entry boundary that routes API traffic and applies shared policies before requests reach backend services.

- Type: framework
- Domain: Engineering & architecture
- Level: Intermediate
- Last reviewed: 2026-09-24
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/api-gateway/>)

## What it means

An API gateway is a component positioned between API consumers and backend services. It receives requests, selects a destination, and may handle cross-cutting concerns such as authentication enforcement, rate limits, protocol translation, response aggregation, logging, and traffic policy. It is an application-facing boundary, whereas a load balancer primarily distributes traffic among eligible targets.

## Why it matters

A gateway can give clients one stable interface while internal services change and can enforce important policies consistently. It also concentrates latency, configuration, security, and availability risk, so teams need clear ownership and restraint about which logic belongs there.

## When to use it

Use an API gateway when multiple services need a shared external boundary, consistent traffic policy, or client-oriented routing and composition. A direct service endpoint or simple load balancer may be sufficient for a small system with one backend and few cross-cutting policies.

## How it works

1. Define the client-facing routes, protocols, ownership, and compatibility contract.
2. Authenticate callers and apply authorization, quota, and request-validation policies at suitable layers.
3. Route each accepted request to a healthy backend or compose a bounded response.
4. Transform protocols or payloads only where the benefit exceeds added coupling.
5. Propagate correlation, identity, deadlines, and errors without hiding backend behavior.
6. Monitor gateway latency, rejection reasons, route health, policy changes, and availability.

## A practical example

A marketplace exposes one mobile API boundary for catalog, accounts, and orders. The gateway verifies tokens, applies per-client limits, and routes requests to separately deployed services, while business pricing logic remains inside the owning services.

## Where it breaks

A gateway can become a bottleneck, single failure domain, or central team queue. Excessive response composition and business logic couple releases and make debugging harder. It does not remove the need for service-level authorization, resilience, or contract governance.

## Common mistakes

- Treating the gateway as the only authorization layer for sensitive backend actions.
- Moving changing business logic into shared routing configuration.
- Confusing API management and composition needs with simple load distribution.
- Adding a gateway without redundancy, policy testing, or end-to-end tracing.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/api-gateway/#visualization-api-gateway>)

## Sources

1. [What Is Amazon API Gateway?](<https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html>) — Amazon Web Services · Official technical documentation
2. [Gateway Routing Pattern](<https://learn.microsoft.com/en-us/azure/architecture/patterns/gateway-routing>) — Microsoft Learn · Institutional architecture guide

## Related topics

- [Application Programming Interface \(API\)](<https://wiki.soroush.uk/topic/application-programming-interface/>)
- [Load Balancer](<https://wiki.soroush.uk/topic/load-balancer/>)
- [Rate Limiting](<https://wiki.soroush.uk/topic/rate-limiting/>)
