In a microservices architecture with dozens of backend services, should the client (mobile app or web browser) communicate directly with each service? If a single page requires data from the User Service, Product Service, and Recommendation Service, the client would need to make three separate HTTP requests to three different URLs. This is inefficient and exposes internal service details.
An API Gateway solves this by acting as a single entry point for all client requests.
The API Gateway sits between the client and the backend microservices. The client sends all requests to one URL (the gateway). The gateway routes each request to the appropriate backend service, aggregates the responses if needed, and returns a single unified response to the client.
/api/users/* to the User Service, /api/orders/* to the Order Service, etc./api/dashboard might internally require data from 5 different microservices. The gateway fetches all 5 in parallel and returns a single combined response.Different clients (mobile app, web browser, smart TV) often have very different data requirements. A mobile app on a slow 4G connection needs a minimal, compressed response. A desktop web app needs a full, rich response.
The BFF Pattern creates a separate API Gateway for each client type. The Mobile BFF gateway returns minimal payloads, while the Web BFF gateway returns full payloads. Each BFF is optimized for its specific client.