Resilience & Service PatternsAPI Gateway PatternsEasy⏱️ ~3 min

What is an API Gateway and Why Use One?

Definition
API Gateway is a server that acts as the single entry point for all client requests, routing them to appropriate backend services while handling cross cutting concerns like authentication, rate limiting, and protocol translation.

The Problem Without a Gateway

Without a gateway, clients must know the address of every service. A mobile app rendering a product page needs to call the product service, inventory service, pricing service, and reviews service separately. This creates 4 round trips over the network, each adding 50-200ms latency on mobile networks. Clients also need to handle service discovery, authentication with each service, and protocol differences.

What the Gateway Provides

The gateway presents a unified API to clients. Instead of 4 calls, the client makes 1 call to the gateway, which fans out to backend services over the fast internal network (1-2ms latency). The gateway handles authentication once, translates protocols (REST to gRPC), and aggregates responses. Clients are decoupled from internal service topology changes.

Core Gateway Functions

Routing: Direct requests to correct backend service based on path, headers, or content. Composition: Aggregate multiple service responses into one. Protocol translation: Convert between REST, gRPC, WebSocket, GraphQL. Cross cutting concerns: Authentication, rate limiting, logging, metrics collection applied uniformly.

💡 Key Insight: The gateway trades a single point of failure for simplified client logic and centralized policy enforcement. This trade off is usually worthwhile when you have many services and diverse clients.

Gateway vs Service Mesh

Gateways handle north south traffic (external clients to internal services). Service meshes handle east west traffic (service to service). A gateway sits at the edge; a mesh sits between services. Most architectures use both: gateway for external API, mesh for internal communication.

💡 Key Takeaways
Gateways reduce client round trips from N service calls to 1 gateway call, saving 50-200ms per eliminated hop on mobile
Core functions: routing, response composition, protocol translation, and centralized cross cutting concerns
Gateway handles north south traffic (external to internal); service mesh handles east west (service to service)
📌 Interview Tips
1Start by explaining the round trip problem: mobile clients making 4 separate calls adds 200-800ms latency
2Distinguish gateway from service mesh immediately to show you understand the architecture layers
3Mention protocol translation as a key benefit when backend uses gRPC but clients need REST
← Back to API Gateway Patterns Overview