What is an API gateway?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for System Design development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
An API gateway is a server that acts as the single entry point for all client requests to a microservices backend. It handles cross-cutting concerns so individual services don't have to. Functions of an API gateway: (1) Request routing: routes requests to the appropriate backend service based on URL path, headers, or other criteria; (2) Authentication/Authorization: validates JWT tokens or API keys once at the gateway, so services don't each need auth logic; (3) Rate limiting: throttle requests per client; (4) SSL termination: handle HTTPS at the gateway, forward plain HTTP internally; (5) Load balancing: distribute requests across service instances; (6) Request/response transformation: translate between client and service formats; (7) Caching: cache common responses; (8) Logging and monitoring: centralized observability; (9) Circuit breaking: stop forwarding to unhealthy services; (10) API composition: aggregate data from multiple services into one response (Backend for Frontend pattern). Examples: AWS API Gateway, Kong, NGINX, Traefik, Netflix Zuul, Apigee. BFF (Backend for Frontend) pattern: separate API gateways for different client types (mobile BFF, web BFF) — each gateway optimized for its client's needs. Trade-off: gateway adds a hop and becomes a potential bottleneck/single point of failure — deploy redundantly.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex System Design answers easy to follow.