Single Entry Point
API Gateway provides one door for all clients. Hides microservices complexity.
When you have multiple microservices, clients need to know about each one:
Problems:
Solution: API Gateway - A single entry point that routes requests, handles cross-cutting concerns, and aggregates responses.
API Gateway is a single entry point that sits between clients and microservices. It acts as a reverse proxy that routes client requests to appropriate backend services, handles cross-cutting concerns like authentication and rate limiting, and can aggregate responses from multiple services.
Instead of clients directly calling multiple microservices, they make requests to a single API Gateway. The gateway handles routing, security, monitoring, and other cross-cutting concerns, allowing backend services to focus on business logic. This pattern simplifies client code, centralizes security, and provides a unified interface to your microservices architecture.
Route requests to appropriate services:
Routing Examples:
| Request | Route To |
|---|---|
GET /api/users/123 | User Service |
POST /api/orders | Order Service |
GET /api/products | Product Service |
POST /api/payments | Payment Service |
Centralized security:
Benefits:
Control request volume per client:
Combine multiple service calls:
Without Gateway (Multiple Requests):
Client → User Service (get user)Client → Order Service (get orders)Client → Product Service (get products)= 3 round tripsWith Gateway (Aggregation):
Client → Gateway → [User, Order, Product Services] → Gateway → Client= 1 round tripJust route requests:
Client → Gateway → ServiceUse when:
Gateway tailored for specific client:
Aggregates multiple service calls:
Client → Gateway → [Service1, Service2, Service3] → Gateway → ClientUse when:
| Solution | Type | Best For |
|---|---|---|
| Kong | Open source | General purpose, plugin ecosystem |
| AWS API Gateway | Managed | AWS ecosystem |
| Zuul | Open source | Netflix stack, Spring Cloud |
| Envoy | Open source | Service mesh, high performance |
| NGINX | Open source | Simple routing, high performance |
At the code level, gateways translate to routing logic, middleware, and aggregation patterns.
Single Entry Point
API Gateway provides one door for all clients. Hides microservices complexity.
Request Aggregation
Combine multiple service calls into one request. Reduces round trips significantly.
Centralized Security
Handle authentication, authorization, and rate limiting in one place. Services stay simple.
Load Balancing
Gateway can distribute load across service instances. Services don’t need to know about each other.