β Back to Gallery
π―
Backend for Frontend Pattern
Definition
The Backend for Frontend (BFF) Pattern creates separate backend services for different frontend applications or user experiences. Each BFF is tailored to the specific needs of its frontend, providing optimized APIs and data aggregation rather than forcing all clients to use a generic API.
When to Use It
- Supporting multiple client types (web, mobile, IoT)
- Different frontends have significantly different needs
- You want to optimize APIs for specific client experiences
- Reducing over-fetching or under-fetching of data
- Teams are organized by frontend platforms
- Need for client-specific business logic
Pros & Cons
β Pros
- Optimized APIs for each client type
- Reduced payload size for mobile
- Frontend teams have more autonomy
- Easier to evolve client-specific features
- Better separation of concerns
- Reduced coupling between clients and services
β Cons
- Code duplication across BFFs
- More services to maintain
- Potential inconsistencies between BFFs
- Increased operational complexity
- Risk of logic leaking into BFFs
- More deployment pipelines
Architecture Diagram
Without BFF (Generic API for all clients):
βββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββ ββββββββββββ ββββββββββββ
β Web β β Mobile β β IoT β
β Client β β App β β Device β
ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ
β β β
βββββββββββββββ΄ββββββββββββββ
β
βΌ
ββββββββββββββββββ
β Generic API β ββ One size fits none
β Gateway β β’ Over-fetching
ββββββββββ¬ββββββββ β’ Under-fetching
β β’ Complex clients
βββββββββββββΌββββββββββββ
βΌ βΌ βΌ
ββββββββββ ββββββββββ ββββββββββ
β User β βProduct β β Order β
βService β βService β βService β
ββββββββββ ββββββββββ ββββββββββ
With BFF (Tailored APIs):
ββββββββββββββββββββββββββ
ββββββββββββ ββββββββββββ ββββββββββββ
β Web β β Mobile β β IoT β
β Client β β App β β Device β
ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ
β β β
β Rich data β Optimized β Minimal
β GraphQL β REST/JSON β Binary
βΌ βΌ βΌ
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β Web BFF β β Mobile BFF β β IoT BFF β
β β β β β β
β β’ Full data β β β’ Small β β β’ Status β
β β’ Complex β β payloads β β only β
β queries β β β’ Paginationβ β β’ Commands β
β β’ Admin β β β’ Caching β β β’ Telemetry β
ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ
β β β
ββββββββββββββββββΌβββββββββββββββββ
β
βββββββββββββΌββββββββββββ
βΌ βΌ βΌ
ββββββββββ ββββββββββ ββββββββββ
β User β βProduct β β Order β
βService β βService β βService β
ββββββββββ ββββββββββ ββββββββββ
Example: Product Page Request
ββββββββββββββββββββββββββββββ
Web BFF Response (Rich):
{
"product": {...},
"reviews": [...],
"recommendations": [...],
"inventory": {...},
"pricing": {...},
"seller": {...}
}
Mobile BFF Response (Optimized):
{
"product": {
"id": "123",
"name": "...",
"price": 29.99,
"image": "thumbnail_url"
},
"rating": 4.5,
"inStock": true
}
IoT BFF Response (Minimal):
{
"id": "123",
"price": 29.99,
"available": 1
}
Key Principles:
β’ Each BFF owned by frontend team
β’ Business logic stays in services
β’ BFF handles aggregation & formatting
β’ Keep BFFs thin (avoid duplication)