What is Backend for Frontend
Separate backend for each frontend
BFF (Backend for Frontend)
Backend for Frontend — an architectural pattern where a separate backend layer is created for each type of client (web, mobile app, IoT).
Why BFF is Needed
| Problem without BFF | Solution with BFF | |--------------------|-------------------| | One API for all clients | Optimized API for each client | | Excessive data in responses | Only needed fields for specific UI | | Complex logic on client | Data aggregation on server | | Slow loading on mobile | Minimized requests and data |
Architecture
[Web App] → [Web BFF] ↘
→ [Microservices]
[Mobile App] → [Mobile BFF] ↗
When to Use
- Different clients — web, iOS, Android with different needs
- Microservice architecture — many services to aggregate
- Performance optimization — data minimization for mobile
- Independent teams — separate frontend and backend teams
Advantages
- Optimization for each client type
- Independent deployment
- Change isolation
- Simplified client code
Disadvantages
- Logic duplication between BFFs
- Increased number of services
- Complexity of synchronizing changes