Backends for Frontends
A Backend for Frontend (BFF) is a server-side component built specifically for one kind of user interface or client, which aggregates and adapts calls to underlying services in the shape that client needs.
The pattern was described by Sam Newman, based on experience at SoundCloud.
The problem
A single general-purpose API serving a web app, a mobile app and a partner integration ends up serving none of them well. Mobile wants small payloads and few round trips; web wants rich data; partners want stable, versioned contracts. The shared API grows special cases for each, and every change needs every client team to agree. The API team becomes a bottleneck, which is Conway’s law at work.
The solution
Create a separate, thin backend per type of client:
- the web BFF aggregates several services into what each page needs
- the mobile BFF returns compact responses designed for slow networks and limited battery
- the partner API offers a stable, versioned and well-documented contract
Each BFF is owned by the team that builds its client, so it can change at the client’s pace. BFFs contain presentation and aggregation logic only. Business rules stay in the underlying services.
In the cloud, BFFs are often small serverless functions or containers behind an API gateway. GraphQL is sometimes used as an alternative that lets clients shape their own queries.
When to use it
- Several client types have meaningfully different needs.
- Client teams are being slowed down by a shared API owned by someone else.
- You want to keep chatty, fine-grained service calls on the server side of the network.
Trade-offs
- Duplication: similar aggregation logic may appear in several BFFs. A little duplication is the price of independence, but extract it if it grows.
- More things to run: each BFF needs deploying, securing and observing.
- Logic creep: business rules that leak into BFFs end up inconsistent between clients. Keep them thin.
Like many patterns, BFF is as much about team structure as technology: organise backends around the teams and experiences they serve, and the architecture will follow.