Lesson 12 / 32
API Gateway & Service Discovery
A single front door for clients, and how services find each other.
The single front door
An API gateway sits in front of many backend services and gives clients one endpoint. It handles routing, auth, rate limiting, and response aggregation so each service doesn't reimplement them.
Finding services
With services scaling up and down, hardcoded IPs break. Service discovery (Consul, Eureka, or Kubernetes DNS) keeps a live registry — services register on startup, and callers look up healthy instances at request time.
The building receptionist
The gateway is a receptionist who checks your ID (auth), tells you which floor to go to (routing), and won't let too many visitors in at once (rate limiting) — so individual departments don't each need their own front desk.
Don't let it become a monolith
Keep business logic out of the gateway. It should route and enforce cross-cutting policy, not know about order totals or inventory — otherwise it becomes the new bottleneck.