FresherTechnicalAPI design
What is an API gateway and what does it do?
Try answering first
Model answer
An API gateway is a server that sits in front of your backend services and acts as the single entry point for clients. Think of it as a reception desk: every visitor checks in there, and the desk sends them to the right office.
Typical jobs:
- Routing:
/orders/*goes to the orders service,/users/*to the users service. - Authentication: check API keys or tokens once, instead of in every service.
- Rate limiting and quotas: protect services from abuse.
- TLS termination, logging and metrics in one place.
- Optional extras such as caching, request transformation and response aggregation.
Clients see one stable URL, while services behind it can move, scale or be rewritten.
It is related to, but not the same as, a load balancer (spreads traffic across identical instances) and a reverse proxy (forwards requests). A gateway is a reverse proxy with API-aware features. Examples are Kong, Envoy-based gateways and AWS API Gateway.
The risk is that it becomes a single point of failure, so run several instances.
Key points
- A single entry point in front of backend services
- Handles routing, auth, rate limiting and logging
- A reverse proxy with API-aware features
- Run several instances to avoid a single point of failure
Likely follow-ups
- How is an API gateway different from a load balancer?
- What should you not put in a gateway?
Common mistakes
- Treating the gateway as a place for business logic
- Running a single gateway instance in production