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.
| Stage | What happens | Typical failure response |
|---|---|---|
| TLS termination | Decrypts HTTPS and validates certificates | Connection refused or handshake error |
| Route matching | Maps path, method and host to an upstream | 404 Not Found |
| Authentication | Validates an API key, JWT or OAuth token | 401 Unauthorized |
| Authorization | Checks scopes or roles for the route | 403 Forbidden |
| Rate limiting | Counts requests per client and window | 429 Too Many Requests |
| Transformation | Rewrites headers, paths or payloads | 400 Bad Request on invalid input |
| Upstream call | Forwards to a service with timeouts and retries | 502 Bad Gateway or 504 Gateway Timeout |
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.
| Parameter | Common range or form | Effect |
|---|---|---|
| Rate limit | Tens to thousands of requests per second per client | Protects backends from overload and abuse |
| Upstream timeout | Roughly 1 to 30 seconds | Bounds how long a client waits for a slow service |
| Retry policy | 0 to 3 attempts, idempotent methods only | Masks transient faults, can amplify load |
| Payload size limit | Often 1 MB to 10 MB | Blocks oversized or malicious bodies |
| Response cache TTL | Seconds to minutes | Reduces backend calls for repeatable reads |
| CORS policy | Allowed origins, methods and headers | Controls which browser applications may call the API |
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.
API gateway compared with related components
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.
| Component | Main focus | Traffic direction | API awareness |
|---|---|---|---|
| API gateway | Managing and securing APIs for consumers | North-south, client to services | High: routes, keys, quotas, schemas |
| Reverse proxy | Forwarding and caching HTTP traffic | North-south | Low to moderate |
| Load balancer | Distributing connections across instances | Any | Minimal, often layer 4 |
| Service mesh | Service-to-service security and reliability | East-west, between services | Moderate, per-call policies |
| Backend for frontend | Tailoring responses to one client type | North-south | High, contains client logic |
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.
| Situation | Recommended pattern | Reason |
|---|---|---|
| Small product with a few services | Single shared gateway | Lowest operational overhead |
| Web, mobile and partner clients with different needs | Gateway plus backends for frontends | Avoids one interface serving conflicting demands |
| Many autonomous teams | Federated gateways per domain | Removes a central bottleneck for changes |
| Strict data residency rules | Regional gateway instances | Keeps traffic and logs within each region |
| Serverless functions as backends | Managed cloud gateway | Native integration and automatic scaling |
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.