Backend for Frontend (BFF)
A dedicated backend per client experience that aggregates and shapes APIs, owned by the front-end team, with guidance on when GraphQL federation is a better fit.
Intent
Described by Sam Newman (originating at SoundCloud), a BFF is a backend built specifically for one user experience (web, iOS, Android, smart TV). It aggregates downstream service calls, shapes payloads for that client, and handles client-specific concerns (auth flows, pagination style, caching).
flowchart LR WEB[Web SPA] --> BW[Web BFF<br/>owned by web team] IOS[iOS app] --> BM[Mobile BFF<br/>owned by mobile team] AND[Android app] --> BM BW --> P[Product svc] BW --> R[Review svc] BM --> P BM --> O[Order svc]
Java example: aggregate in parallel with virtual threads
@RestController
class ProductPageController {
private final ProductClient products; private final ReviewClient reviews; private final PriceClient prices;
ProductPageController(ProductClient p, ReviewClient r, PriceClient pr) { products = p; reviews = r; prices = pr; }
@GetMapping("/bff/web/products/{id}")
ProductPage page(@PathVariable String id) throws Exception {
try (var scope = Executors.newVirtualThreadPerTaskExecutor()) {
var product = scope.submit(() -> products.get(id));
var price = scope.submit(() -> prices.get(id));
var top = scope.submit(() -> reviews.top(id, 3)); // optional: fallback inside client
return new ProductPage(product.get(1, SECONDS), price.get(1, SECONDS), top.get(300, MILLISECONDS));
}
}
}Pros and cons
| Pros | Cons |
|---|---|
| Optimized payloads per client; fewer round trips | Duplication across BFFs |
| Front-end team autonomy | More deployables |
| Isolates client-specific changes from core services | Risk of business logic creeping into BFFs |
Alternatives
- GraphQL (single graph or federation): clients request exactly the fields they need; good when many clients with varied needs share data.
- Gateway aggregation: simple cases, but keep the gateway thin.
Interview questions
One BFF per platform or per team?
Per user experience and owning team. iOS and Android often share one mobile BFF if their needs are the same; separate them only if their requirements diverge.
BFF or GraphQL?
GraphQL reduces the need for multiple BFFs by letting clients shape queries, at the cost of schema governance and query-cost control. A GraphQL server can itself act as a BFF.