REST API Gateway
A system with many APIs creates a problem for clients. Which address do they call, and how do they log in to each one? An API gateway answers both questions. It acts as a single front door for all backend services.
The Hotel Front Desk Picture
Guests in a hotel do not walk into the kitchen, the laundry, and the maintenance room to ask for things. They visit the front desk. Staff check the guest identity, pass each request to the right department, and bring back the answer. The gateway performs this role for APIs.
Where the Gateway Sits
Mobile App ──┐ ┌──→ Users Service Web App ─────┼──→ API GATEWAY ─────┼──→ Orders Service Partner ─────┘ (one public URL) └──→ Payments Service
Core Jobs
| Job | What It Does |
|---|---|
| Routing | Sends /users to the Users service and /orders to the Orders service |
| Authentication | Checks tokens or API keys once at the edge |
| Rate limiting | Stops any client from sending too many requests |
| Caching | Stores common responses and answers without calling the backend |
| Transformation | Changes headers, paths, or formats between client and service |
| Logging | Records every request in one place |
| TLS termination | Handles HTTPS so internal services stay simple |
A Request Through the Gateway
Request: GET /orders/7 Authorization: Bearer ... │ ▼ 1. TLS decrypt 2. Check token ──── invalid? ──→ return 401 3. Check rate limit ─ exceeded? ─→ return 429 4. Check cache ───── hit? ──────→ return cached answer 5. Route to Orders Service 6. Log request and response time │ ▼ Response returns to client
Every request passes the same checks, so no backend service repeats the work.
Gateway, Reverse Proxy, and Load Balancer
These three tools overlap. A load balancer spreads traffic across copies of one service. A reverse proxy forwards requests to servers and may add caching or TLS. An API gateway includes those abilities and adds API-specific features such as key management, usage plans, and request transformation.
The Backend for Frontend Pattern
A phone screen and a web dashboard need different data. One gateway layer per client type, called a Backend for Frontend, shapes responses for each. The mobile gateway returns compact payloads, and the web gateway returns richer ones.
Mobile App ──→ Mobile Gateway ──┐ Web App ─────→ Web Gateway ─────┼──→ Shared Services
Aggregation
A dashboard may need a user profile, recent orders, and account balance. The gateway can call three services and merge the answers into one response. The client makes a single call, and the gateway handles the rest.
Popular Options
Cloud providers offer managed gateways such as Amazon API Gateway and Azure API Management. Open-source choices include Kong, NGINX, and Envoy. Managed products reduce operations work, and open-source products offer more control.
Risks to Manage
- The gateway becomes a single point of failure. Run several copies behind a load balancer.
- Heavy logic inside the gateway makes it a bottleneck. Keep business rules in the services.
- Every extra hop adds a small delay. Measure gateway latency.
- Configuration mistakes affect every API. Review changes and test them before release.
Common Mistakes
Skipping Internal Security
Gateway checks do not replace service-level checks. A service reachable from inside the network still needs its own authorization.
One Giant Gateway for Everything
A single gateway that serves every team becomes a slow shared dependency. Split by domain or client type when the load grows.
Ignoring Versioning
Route /v1 and /v2 paths to different service versions at the gateway. Clients migrate at their own pace.
