API Gateway Pattern: Single Entry Point for Microservices
Fast recall
Quick revision
Core answer
What concerns belong in the gateway vs in services, BFF (Backend-for-Frontend) pattern, and operational considerations.
Putting business logic in the gateway (turns into a monolith), or skipping the gateway and forcing every service to handle auth/rate-limit/CORS itself.
Distinguish edge gateway vs internal service mesh, discuss BFF for client-specific aggregation, mention deployment patterns (canary at gateway level), and the gateway-as-bottleneck trap.
Interview-ready guide
Interview answer
The problem it solves
Without a gateway, every microservice has to implement auth, rate limiting, TLS, CORS, logging, tracing, request validation — the cross-cutting concerns. With 50 services, that's 50 different implementations drifting apart, security gaps everywhere, every team reinventing the wheel.
The API Gateway centralizes those concerns into one tier. Clients talk to one URL; the gateway handles auth, rate-limiting, routing, observability, then forwards to the right backend service.
What belongs in the gateway
Always: TLS termination, auth (JWT/OAuth validation), rate limiting, logging, metrics, distributed tracing header propagation, routing, basic input validation, CORS, security headers.
Sometimes: response caching, request/response transformation (REST ↔ gRPC), aggregation for BFF, circuit breaking, retries, canary routing, A/B test injection.
Never: business logic. The moment the gateway knows that 'an order with status SHIPPED can't be cancelled,' it's become a microservice itself — a coupling disaster. Validate JSON shape sure; validate 'productId 42 in stock' is the product service's job.
BFF — Backend-for-Frontend
Mobile apps need different data shapes than web. Forcing both into one API leads to over-fetching or under-fetching. Solution: one gateway per client type — mobile BFF, web BFF, partner API gateway.
Each BFF can:
- Aggregate multiple service calls into one response (product page = product + reviews + recommendations)
- Serve different formats (Protobuf for mobile size, JSON for web)
- Iterate independently — owned by the client team
GraphQL gateways are a fancy BFF flavor — client picks fields, gateway federates to services.
Edge gateway vs service mesh — different layers
Edge gateway: north-south traffic. Sits between clients and services. Auth, rate-limit per API key, public TLS. Kong, AWS API Gateway, Spring Cloud Gateway.
Service mesh: east-west traffic. Sits between services as sidecars. mTLS, retries, circuit breaking, traffic shifting. Istio, Linkerd.
Mature microservices have both. Lighter setups skip the mesh and let the gateway handle some cross-service concerns.
Operational realities
Gateway = critical path. If it goes down, everything goes down.
- HA: multiple instances, multi-AZ, graceful drain on deploys
- Latency: adds 1-5ms baseline; avoid sync remote calls in the request path; cache auth/rate-limit aggressively
- Config drift: hundreds of routes; declarative config (Kong DB-less, YAML), CI-controlled deploys
- Security: don't trust client headers — strip, then add gateway-set ones (
X-Auth-User) - Versioning: route by header or URL prefix (
/v1,/v2); sunset headers for deprecation
When NOT to use a gateway
- Tiny systems: an NGINX + a lambda for auth is enough
- Pure internal systems with no external traffic: service mesh might suffice
- Strict <5ms latency budget: the hop may be too expensive
- Gateway logic creep: thousands of lines of conditional transforms = it's becoming a service. Split into a BFF or push back into the actual service.
Recommendation
Use an API Gateway for any system with multiple microservices and external clients. Centralize TLS, auth, rate limiting, observability — keep business logic out. For multiple client types, layer BFFs on top per client. Pair with a service mesh for east-west zero-trust. Treat the gateway as critical infrastructure: HA across AZs, low baseline latency, declarative config under CI control. Common picks: Kong, Spring Cloud Gateway, AWS API Gateway for managed; Envoy or Istio Ingress for self-hosted.
API Gateway Pattern: Single Entry Point for Microservices
Direct Answer
An API Gateway is a single front-door that sits between clients and backend microservices, handling authentication, rate limiting, routing, request/response transformation, protocol translation, and observability in one place. It eliminates the need for every microservice to reimplement cross-cutting concerns and shields clients from the messy reality of which service owns what. The trade-off is operational risk — the gateway becomes a critical chokepoint that needs to be highly available, low-latency, and carefully versioned. Examples: Kong, AWS API Gateway, Spring Cloud Gateway, Envoy, Netflix Zuul.
Common Mistakes & Pitfalls
Putting business logic in the gateway (turns into a monolith), or skipping the gateway and forcing every service to handle auth/rate-limit/CORS itself.
Check your understanding
Answer these without looking back at the article.
- Design a multi-tenant API gateway that enforces different rate limits per customer plan.
- How do you handle a gradual rollout of a new microservice version using the gateway?
- Walk through the failure modes when the gateway can't reach the auth provider.
- When would you use GraphQL federation instead of a traditional API gateway?
Related interview prep categories
2Want a guided curriculum order?
These modules are also sequenced in our flagship backend interview track — open it when you prefer an ordered path instead of browsing by topic.