Prompt
What's the difference between an API gateway and a Backend for Frontend?
Latest observation
An API Gateway and a Backend for Frontend (BFF) both sit between clients and backend services, but they solve different problems.
API Gateway
A gateway is a generic entry point for many clients and many backend services.
Main purpose
- Route requests to the right service
- Handle cross-cutting concerns:
- authentication/authorization
- rate limiting
- logging/metrics
- request/response transformation
- SSL termination
- Hide internal service topology
Characteristics
- Usually shared by multiple clients: web, mobile, partner apps, etc.
- Usually organization/platform-oriented
- Not usually tailored heavily to one specific UI
- Can be “thin” and mostly pass-through
Example
/users/123 gets routed to the User Service, /orders/456 to the Order Service.
Backend for Frontend (BFF)
A BFF is a backend built for a specific frontend or client type.
Main purpose
- Provide exactly the data and shape a particular UI needs
- Reduce chatty calls from the frontend
- Aggregate data from multiple downstream services
- Encapsulate frontend-specific logic
Characteristics
- Usually one BFF per frontend:
- web BFF
- mobile BFF
- admin dashboard BFF
- Optimized for a particular user experience
- Often does orchestration and composition
- May expose endpoints that don’t map cleanly to internal services
Example
A mobile app may want:
- user profile
- recent orders
- notifications
all in one response from
/home-screen
The BFF combines data from multiple services and returns a mobile-friendly payload.
Key difference in one sentence
- API Gateway = shared infrastructure for routing and policy enforcement
- BFF = client-specific backend optimized for a particular frontend
Comparison
| Aspect | API Gateway | BFF |
|---|---|---|
| Audience | Multiple clients | One specific frontend/client type |
| Focus | Infrastructure and policies | UI-specific data and orchestration |
| Scope | Broad, generic | Narrow, tailored |
| Data shaping | Minimal to moderate | Heavy, frontend-oriented |
| Number of instances | Usually one per platform/edge | Often one per frontend |
| Typical ownership | Platform/backend team | Frontend/product team or joint |
Can they be used together?
Yes. Common setup:
Client → BFF → API Gateway → Microservices
Or sometimes:
Client → API Gateway → BFF → Microservices
Though in many architectures, the BFF is the “edge” backend and the gateway may sit behind it or be folded into it depending on the team and scale.
Rule of thumb
- Use an API Gateway when you need shared ingress, security, routing, and operational control.
- Use a BFF when a frontend needs a custom backend tailored to its UX and data needs.
If you want, I can also give you a real-world architecture diagram or when to choose one vs the other.