Skip to main content

API Gateway Patterns for Microservices

·APIScout Team
api gatewaymicroserviceskongapi architecturebackend

API Gateway Patterns for Microservices

An API gateway sits between clients and your microservices, handling cross-cutting concerns — routing, authentication, rate limiting, request transformation, and aggregation. Without a gateway, every microservice implements these concerns independently (or doesn't).

Core Gateway Patterns

1. Reverse Proxy / Router

The simplest pattern. The gateway routes requests to the correct service based on URL path, headers, or other criteria.

Client → Gateway → /users/* → User Service
                  → /orders/* → Order Service
                  → /products/* → Product Service

Use when: You want a single entry point without duplicating routing logic across services.

2. API Aggregation (Backend for Frontend)

The gateway combines data from multiple services into a single response. The client makes one request instead of three.

Client: GET /api/dashboard
Gateway:
  → GET user-service/profile
  → GET order-service/recent
  → GET analytics-service/metrics
  → Combine → Single response

Use when: Frontend pages need data from multiple services. Reduces client-side complexity and round trips.

3. Authentication Gateway

The gateway handles authentication (JWT validation, API key verification) so individual services don't need to. The gateway passes the validated identity downstream via headers.

Client → Gateway (validate JWT) → X-User-Id: 123 → Service

Use when: You want centralized authentication instead of each service validating tokens independently.

4. Rate Limiting Gateway

The gateway enforces rate limits before requests reach your services. Protects backend services from abuse and ensures fair usage.

Use when: Multiple services need consistent rate limiting policies.

5. Request/Response Transformation

The gateway transforms requests and responses — header manipulation, body modification, protocol translation (REST → gRPC), and response filtering.

Client (REST/JSON) → Gateway (transform) → Service (gRPC/Protobuf)

Use when: Internal services use different protocols than external clients expect.

6. Circuit Breaker

The gateway monitors service health. When a service fails repeatedly, the gateway "opens the circuit" — returning cached responses or errors without forwarding requests to the failing service.

Use when: Cascading failures are a risk (one slow service brings down everything).

Gateway vs Service Mesh

ConcernAPI GatewayService Mesh (Istio/Linkerd)
PositionEdge (external traffic)Internal (service-to-service)
AuthExternal client authmTLS between services
Rate limitingPer-client limitsPer-service limits
RoutingURL path, host, headersService name, labels
ObservabilityExternal request metricsInternal traffic metrics
Aggregation✅ Yes❌ No
ComplexityMediumHigh

Most architectures use both: Gateway at the edge for external traffic + service mesh for internal communication.

Choosing a Gateway

GatewayBest ForType
KongSelf-hosted, plugin ecosystemOpen source
ZuploEdge-deployed, developer-firstCloud
AWS API GatewayServerless + LambdaCloud
EnvoyService mesh, high performanceOpen source
TraefikKubernetes-nativeOpen source
NGINXSimple reverse proxyOpen source
CloudflareEdge + securityCloud

Anti-Patterns

Anti-PatternProblemSolution
Business logic in gatewayGateway becomes a monolithKeep gateway thin — routing, auth, rate limiting only
Gateway as single point of failureOne gateway failure = total outageMultiple gateway instances, health checks
Over-aggregationGateway becomes tightly coupled to all servicesLimit aggregation to BFF patterns
No circuit breakerSlow service blocks gateway threadsImplement timeouts and circuit breakers
Gateway per teamInconsistent policies, management overheadShared gateway with per-team configuration

Building microservices architecture? Explore Kong, API gateways, and more on APIScout — comparisons, guides, and developer resources.

Comments