<< back to Guides
<< back to Guides
π§© Backends-for-Frontends (BFF) β Quick Guide
Backends-for-Frontends (BFF) is a design pattern where you create a dedicated backend for each frontend (e.g., web, mobile, IoT). It helps tailor API responses, reduce over-fetching, and decouple frontend and backend teams.
π§ What Is BFF?
A BFF is a service layer that sits between frontend applications and backend APIs or services. Each frontend (like Web, iOS, Android) can have its own BFF that caters specifically to its needs.
π― Why Use BFF?
- β Tailor APIs to frontend needs (no over-fetching/under-fetching).
- β Encapsulate frontend-specific logic (formatting, transformations).
- β Enable faster frontend iteration without breaking backend services.
- β Manage authentication, rate limits, caching, aggregation.
- β Help enforce separation of concerns between frontend and backend.
π§± Common Patterns
1. Device-Specific BFFs
Create separate BFFs for Web, Mobile, and others.
bff-web.example.com
bff-mobile.example.com
2. Unified Gateway + BFF
Use an API Gateway for routing + lightweight BFFs for logic.
3. Micro-BFFs
Frontend teams own and deploy their own micro-BFFs per domain or module.
4. Monolith BFF
One BFF service handles all frontend types. Useful for small teams.
βοΈ Responsibilities of a BFF
- Aggregate responses from multiple microservices
- Transform data formats for frontend needs
- Authenticate users and manage tokens
- Handle rate limiting or feature toggles
- Perform caching or batching
- Apply localization or feature experiments
π¦ Example Use Case
GET /dashboard (from Mobile BFF)
β Aggregates:
- User Profile Service
- Notifications Service
- Billing Service
β Returns mobile-optimized response
π When Not to Use BFF
- When all clients can use the same generic backend.
- If your team is too small to maintain multiple backend layers.
- When API Gateway alone can do basic transformations.
β Best Practices
- Co-locate frontend and BFF teams for tight feedback loops.
- Keep BFF stateless and scalable.
- Use versioning to avoid breaking clients.
- Limit business logic in BFF β push that to backend services.
π Summary
Benefit | Description |
---|---|
Tailored APIs | Custom responses per device |
Frontend Agility | Changes in BFF donβt require backend changes |
Simplified Frontend | Aggregates and flattens complex data |
Decoupled Logic | Keeps UI logic out of core services |