API gateway

On this page 7

An API gateway is a server or managed service that acts as the single entry point for client requests to a set of backend services, handling routing, authentication, rate limiting, transformation and monitoring before traffic reaches the code that implements each API. In the field of APIs, it is the component that turns many internal services into one coherent public interface.

The pattern became common with microservice architectures, where a single product may be served by dozens of independently deployed services. Without a gateway, every client would need to know each service address and every service would need to repeat the same security and traffic controls. The gateway centralizes these cross-cutting concerns so that service teams can focus on business logic.

How an API gateway processes a request

An API gateway processes each call as a pipeline of policies executed in a fixed order. A request arrives at a public hostname, passes through TLS termination, is matched against route definitions, and is then subjected to checks before being forwarded to an upstream service. The response travels back through the same pipeline, where headers can be added and payloads reshaped.

The table below summarizes the typical stages in that pipeline and the purpose of each.

StageWhat happensTypical failure response
TLS terminationDecrypts HTTPS and validates certificatesConnection refused or handshake error
Route matchingMaps path, method and host to an upstream404 Not Found
AuthenticationValidates an API key, JWT or OAuth token401 Unauthorized
AuthorizationChecks scopes or roles for the route403 Forbidden
Rate limitingCounts requests per client and window429 Too Many Requests
TransformationRewrites headers, paths or payloads400 Bad Request on invalid input
Upstream callForwards to a service with timeouts and retries502 Bad Gateway or 504 Gateway Timeout
Typical stages of a gateway request pipeline

Because every request passes through this pipeline, the gateway is also the natural place for observability. It emits access logs, latency metrics and distributed tracing headers, which gives operators a consistent view of all traffic regardless of the language or framework used behind it.

Core responsibilities and configuration parameters

A gateway is configured mostly through declarative policies rather than code. Teams define routes, upstream targets and limits in configuration files or an administrative API, often generated from an OpenAPI specification so that documentation and enforcement stay aligned.

ParameterCommon range or formEffect
Rate limitTens to thousands of requests per second per clientProtects backends from overload and abuse
Upstream timeoutRoughly 1 to 30 secondsBounds how long a client waits for a slow service
Retry policy0 to 3 attempts, idempotent methods onlyMasks transient faults, can amplify load
Payload size limitOften 1 MB to 10 MBBlocks oversized or malicious bodies
Response cache TTLSeconds to minutesReduces backend calls for repeatable reads
CORS policyAllowed origins, methods and headersControls which browser applications may call the API
Key gateway parameters and what they control

Values depend heavily on the workload. A public API for mobile clients usually needs strict per-key limits and short timeouts, while an internal batch interface may accept larger payloads and longer waits. The most common configuration error is enabling retries on non-idempotent requests, such as payment submissions, which can cause duplicate operations.

An API gateway overlaps with several other network components, and the boundaries are often blurred by vendors. The distinction lies in which layer the component understands and who its primary consumer is.

ComponentMain focusTraffic directionAPI awareness
API gatewayManaging and securing APIs for consumersNorth-south, client to servicesHigh: routes, keys, quotas, schemas
Reverse proxyForwarding and caching HTTP trafficNorth-southLow to moderate
Load balancerDistributing connections across instancesAnyMinimal, often layer 4
Service meshService-to-service security and reliabilityEast-west, between servicesModerate, per-call policies
Backend for frontendTailoring responses to one client typeNorth-southHigh, contains client logic
Gateway versus neighboring infrastructure

Many gateways are built on reverse proxies such as NGINX or Envoy, so the difference is largely the API management layer added on top: consumer onboarding, key issuance, usage plans and analytics. A gateway may also expose REST APIs, GraphQL or gRPC side by side and translate between protocols, for example presenting a JSON interface to browsers while calling gRPC services internally.

Deployment patterns and when to use them

Organizations deploy gateways in several shapes, and the right choice depends on team structure, traffic volume and latency budget. The following decision table outlines the common options.

SituationRecommended patternReason
Small product with a few servicesSingle shared gatewayLowest operational overhead
Web, mobile and partner clients with different needsGateway plus backends for frontendsAvoids one interface serving conflicting demands
Many autonomous teamsFederated gateways per domainRemoves a central bottleneck for changes
Strict data residency rulesRegional gateway instancesKeeps traffic and logs within each region
Serverless functions as backendsManaged cloud gatewayNative integration and automatic scaling
Choosing a gateway deployment pattern

Whatever the pattern, the gateway must be deployed with high availability: multiple instances across failure zones, health checks on upstreams, and configuration stored in version control. Treating gateway configuration as code allows reviewed, reversible changes instead of manual edits in a console.

Limitations and common mistakes

The main risk of an API gateway is that it becomes a single point of failure and a performance bottleneck. Every request incurs extra processing, typically a few milliseconds, and a misconfigured route or expired certificate can take down every API at once.

  • Putting business logic in the gateway couples it to individual services and turns it into a distributed monolith.
  • Relying only on the gateway for security leaves services exposed if traffic bypasses it, so services should still validate tokens.
  • Global rate limits without per-client keys let one noisy consumer exhaust capacity for everyone.
  • Missing timeouts allow slow upstreams to exhaust gateway connections and cascade failures.
  • Opaque error mapping hides the real cause, so gateways should preserve correlation identifiers in every response.

These problems are manageable with clear ownership, load testing before launches and automated configuration checks. A gateway should stay thin: it enforces policy and routes traffic, while domain rules remain in services.

The short version

An API gateway works like the reception desk of a large office building. Visitors do not wander the corridors looking for the right department. They go to the desk, show identification, and are sent to the correct floor.

The desk also stops people without a badge, limits crowds when too many arrive at once, and keeps a record of who came in. In the same way, the gateway checks, directs and records every request so that the services behind it can concentrate on their own work.

Where it makes a difference

An online retailer runs separate services for catalog, cart, payments and shipping, each owned by a different team. Its mobile app originally called all four services directly, which meant four hostnames, four authentication schemes and no shared view of traffic.

The platform team placed a gateway in front of the services, moved token validation to the gateway, and set a limit of 100 requests per second per app key. A product page that previously required four network round trips now uses one aggregated route, and median page load on mobile networks fell by roughly 300 milliseconds.

During a seasonal sale, a misbehaving partner integration sent bursts of 5,000 requests per second. The gateway answered the excess with 429 responses, and the checkout service stayed available for ordinary customers throughout the event.