Backend for frontend (BFF)
A backend for frontend (BFF) is a small server-side service built for one kind of client: one for the web app, another for the mobile app, perhaps another for a partner portal. Each BFF calls the general-purpose backend services, then combines, filters and reshapes the results into exactly what its screens need.
The pattern was popularized by Phil Calçado and Sam Newman, based on work at SoundCloud. Its main benefit is organizational as much as technical: the team that owns a frontend also owns its BFF, so it can change both together without waiting on a shared API team.
Diagram
Section titled “Diagram”- The web app calls its own BFF, which holds the user's session and tokens server-side.
- The BFF calls several core services and combines the results into one response per screen.
- The mobile app gets a different BFF, tuned for small payloads, slower networks and app release cycles.
How it works
Section titled “How it works”- One BFF per client experience, not per screen and not one for all clients. “Web” and “mobile” is the usual split, because their needs and release cycles differ.
- Aggregation and shaping. One screen often needs data from several services. The BFF calls them, in parallel where possible, and returns one tailored response, reducing round trips from the device.
- Owned by the frontend team. The BFF changes in step with the UI, in the language the team prefers (often TypeScript on Node.js).
- Security: the token-handler pattern. For browser apps, a BFF can perform the OAuth flow server-side and keep access tokens out of JavaScript entirely, using a secure, HTTP-only session cookie with the browser. Current IETF guidance for browser-based apps describes this approach.
- Keep business logic out. A BFF translates and composes. Rules like pricing or eligibility belong in the core services, or they’ll be duplicated in every BFF.
- GraphQL is an alternative, or a BFF implementation: one schema that each client queries for exactly the fields it needs.
- Faster frontend delivery: teams don’t wait on a shared API to add a field.
- Better performance on devices: fewer, smaller responses.
- Better security for browser apps: tokens stay on the server.
- More services to build, deploy and operate.
- Duplication between BFFs if they aren’t kept thin.
- Another network hop, which adds a little latency if the BFF does nothing useful.
When to use it
Section titled “When to use it”- Several client types (web, mobile, partners, devices) with clearly different needs.
- Screens that need data from many services at once.
- Browser apps that should keep OAuth tokens out of the browser.
When to avoid it
Section titled “When to avoid it”With one client and a backend that already fits it, a BFF is an extra hop for no gain. An API gateway may already handle routing, authentication and rate limiting for you.
Common pitfalls
Section titled “Common pitfalls”- One “BFF” shared by every client, which turns into the general-purpose API you were trying to avoid.
- Business rules in the BFF, duplicated and drifting between web and mobile.
- Sequential calls to downstream services instead of parallel ones.
- No ownership: a BFF built by a separate backend team loses most of its benefit.
Related patterns
Section titled “Related patterns”Glossary: API gateway
Further reading
Section titled “Further reading”- Sam Newman, Pattern: Backends For Frontends (opens in a new tab)
- Microsoft, Backends for Frontends pattern (opens in a new tab)
- IETF OAuth Working Group, OAuth 2.0 for Browser-Based Applications (opens in a new tab)
Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.