An API gateway is a server that sits between clients and your backend services and acts as the single entry point for every API request. It routes each request to the right service and handles shared jobs such as authentication, rate limiting and TLS, so each service doesn't have to.
Microsoft's architecture guidance defines it as "a centralized entry point for managing interactions between clients and application services" that "acts as a reverse proxy and routes clients requests to the appropriate services." Amazon's documentation uses a similar picture: the gateway acts as a "front door" for applications to reach data, business logic or functionality in backend services.
What does an API gateway do?
A gateway's work falls into three groups. Microsoft's guide names them as design patterns: routing, aggregation and offloading.
- Routing. The client talks to one address, for example
api.example.com. The gateway looks at the path, method or headers and forwards the request to the matching service. Microsoft describes this as layer-7 routing, meaning the decision is made on the HTTP request itself, not just the IP address and port. - Aggregation. When one screen in an app needs data from several services, the client can send one request to the gateway. The gateway calls the services, combines the results and returns a single response. This reduces the number of round trips between the client and the servers.
- Offloading. Cross-cutting work moves from each service into the gateway. Microsoft's list of examples includes SSL termination, mutual TLS, authentication, IP allow and block lists, client rate limiting (throttling), logging and monitoring, response caching, a web application firewall, GZIP compression and serving static content.
Not every gateway does all of this. Microsoft notes that support for authentication, rate limiting and SSL termination varies between products, so check a product's feature list before you assume a capability.
Why use an API gateway?
The easiest way to see the value is to remove the gateway. Microsoft lists the problems of letting clients call each service directly:
- Client code gets complicated, because it must track many endpoints and handle failures for each.
- Clients become coupled to how the backend is split into services, which makes refactoring harder.
- One operation can need several network round trips, which adds latency.
- Every public service has to implement authentication, SSL and rate limiting itself.
- Services are limited to client-friendly protocols such as HTTP or WebSocket.
- Every public endpoint widens the attack surface.
With a gateway, a team can split one service into two, or move a service to a new host, and only the gateway's routing rule changes. Clients keep calling the same URL.
A request through a gateway, step by step
Suppose a mobile app calls GET https://api.example.com/orders/42. A typical path looks like this:
- The request arrives at the gateway over HTTPS. The gateway terminates TLS, so the connection to the internal service can be handled separately.
- The gateway checks credentials, such as an API key or a token. If they are missing or invalid, it returns
401without bothering the backend. See HTTP status codes explained for what the common codes mean. - The gateway checks the client's rate limit. If the client is over its quota, the gateway answers
429 Too Many Requests. The idea is covered in what rate limiting is. - The gateway matches the path
/orders/42to the orders service and forwards the request to it. - The response travels back through the gateway, which can log it, cache it or compress it before the client receives it.
Example: routing with NGINX
NGINX is a general-purpose reverse proxy that Microsoft lists as one way to build a gateway. Its proxy_pass directive sends matching requests to another server. This sketch routes two path prefixes to two internal services (the host names and ports are made up for the example):
server {
listen 80;
server_name api.example.com;
location /orders/ {
proxy_pass http://orders-service:8001/orders/;
}
location /users/ {
proxy_pass http://users-service:8002/users/;
}
}
The NGINX documentation explains the URI rule: if proxy_pass includes a URI, the part of the request path that matches the location is replaced by that URI; without one, the request URI is passed through unchanged. This config covers routing only. Authentication, per-client limits and usage analytics would need extra directives or a different product. Reverse proxy explained covers the underlying idea.
Example: services and routes in Kong Gateway
Dedicated gateways describe the same thing with their own vocabulary. Kong Gateway uses two objects. A Service points at an upstream API through its url, which fills in the host, port and path. A Route defines how requests are proxied: Kong's docs say that together, Services and Routes "define the path that requests and responses will take through the system." This is Kong's own getting-started example in declarative (decK) format:
_format_version: "3.0"
services:
- name: example_service
url: https://httpbin.konghq.com
routes:
- name: example_route
service:
name: example_service
paths:
- "/mock"
protocols:
- http
- https
Kong's guide shows the two parts applied as separate files, and the one above merges them for brevity. Once applied, a request to /mock/anything on Kong's proxy port is forwarded to the upstream service. Kong's guide returns a 200 response for that request.
Managed gateways: Amazon API Gateway and Azure API Management
If you don't want to run the gateway yourself, cloud providers sell it as a service.
- Amazon API Gateway is described by AWS as a service for "creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket APIs at any scale." It handles traffic management, authorization and access control, monitoring and API version management, and it integrates with AWS Lambda and with other HTTP backends.
- Azure API Management is, per Microsoft, a managed solution for publishing APIs to external and internal customers, with rate limiting, IP restrictions and authentication through Microsoft Entra ID or other identity providers. Microsoft states it does not perform load balancing, so you pair it with a load balancer such as Azure Application Gateway, or with a reverse proxy.
Names can mislead here. Azure Application Gateway, despite the name, is a managed load balancing service with layer-7 routing, SSL termination and a web application firewall. It is not the same product as Azure API Management.
API gateway vs reverse proxy vs load balancer
| Component | Main job | Typical extras |
|---|---|---|
| Reverse proxy | Forward client requests to one or more backend servers | TLS termination, caching, compression |
| Load balancer | Spread traffic across copies of the same service | Health checks, TLS termination |
| API gateway | Single entry point that routes to different services and applies API policies | Authentication, rate limiting, aggregation, usage monitoring |
The categories overlap in practice. Microsoft treats NGINX and HAProxy as reverse proxies that can serve as gateways, and its guidance says the capabilities of the options differ, so you choose by the features you need, not by the label.
When you don't need one
A gateway is one more component to run, secure and keep configured. Microsoft's guide points out that when you add or change services, you may have to update the gateway's routing rules, certificates and allow lists, and recommends infrastructure-as-code and automation to manage that. Because all traffic goes through the gateway, it also becomes a place where an outage or a bad rule affects everything.
For a single application with one backend, the framework's own middleware, or a plain reverse proxy, is usually enough. Microsoft's selection advice goes further: prefer the built-in gateway or ingress your platform already provides, and use a custom gateway only if the built-in options lack the flexibility you need.
Where to go next
If the browser blocks calls from your front end to a gateway on another domain, the cause is usually a missing header, not the gateway itself. CORS error explained walks through that failure.
Frequently asked questions
- Is an API gateway the same as a reverse proxy?
- Not exactly. An API gateway acts as a reverse proxy, but adds API-specific functions such as authentication, rate limiting, request aggregation and usage monitoring. A plain reverse proxy mainly forwards traffic and may balance load or terminate TLS. Many gateways are built on top of reverse proxy software.
- Do I need an API gateway for a small app?
- Usually not. If you have one backend service, a single domain and little need for per-client limits, the web framework or a plain reverse proxy covers it. A gateway pays off when several services sit behind one public address, or when you must apply the same authentication and limits to all of them.
- Is an API gateway the same as a load balancer?
- No. A load balancer spreads traffic across copies of the same service. An API gateway decides which service should receive a request based on the URL, method or headers, and applies policies like authentication on the way. Gateways often work together with load balancers, and some products do both.
- What are examples of API gateways?
- Managed products include Amazon API Gateway and Azure API Management. Open-source and self-hosted options include Kong Gateway, NGINX and HAProxy used as reverse proxies, and the ingress gateway of a service mesh such as Istio.
- Can an API gateway become a single point of failure?
- Yes. Because every request passes through it, an outage or misconfiguration affects every service behind it. Teams usually run several gateway instances behind a load balancer, or use a managed service that provides that availability.