What it is
A Backend for Frontend (BFF) is a server-side component built for one kind of client experience, such as the web app, the mobile app or a partner integration, and usually owned by the team that builds that client. It sits between the client and the general-purpose services, composes the calls a screen needs and returns data in exactly the shape that client renders.
Why it exists
Different clients want different things. A desktop page shows rich detail on a fast connection; a phone shows a compact view over a slow, high-latency link; a smart TV or partner wants something else again. One general-purpose API has to pick a compromise: either large responses that over-serve small clients, or fine-grained endpoints that make them chatty. Worse, every client change becomes a request to the team that owns the shared API, and different client teams ask for conflicting things. A BFF lets each client team build the API its client needs, at its own pace.
How it works
One BFF per experience. Typically one for web and one for mobile (iOS and Android usually share one, because their screens and needs match). Each sits behind the edge gateway, which still handles TLS, authentication and rate limiting; in small setups the BFF may be the gateway route for its client.
Composition. For a screen request the BFF calls the services it needs, in parallel where possible, over the fast internal network, and combines the results. The client makes one round trip instead of several over its slow link.
Shaping. The BFF trims fields, picks image sizes, formats values for display, chooses page sizes, translates errors into what the client can show, and may speak a different protocol to the client (REST or GraphQL) than to the services (often gRPC).
Graceful degradation. Because the BFF knows what its screens need, it can treat some calls as optional: if recommendations time out, return the rest of the screen without them, with a short timeout on optional calls.
Ownership and release. The client team owns the BFF and ships it together with client changes. Mobile releases add one constraint: old app versions stay installed for months, so the mobile BFF must keep supporting the versions still in use.
When to use it
- Clients with clearly different screens, payload needs or network conditions.
- Separate teams per client, blocked by a shared API team.
- Mobile clients that would otherwise make several sequential calls per screen.
- Third-party or partner APIs that need a stable, different contract from your own apps.
When not to
- One team builds every client, or the clients need nearly the same data: one well-designed API is simpler.
- When a flexible query layer (GraphQL with a good schema) already lets clients ask for exactly what they need, a BFF may be redundant, or the GraphQL server effectively is a shared BFF.
- Never as a place for core business rules.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| BFF per client type | Tailored payloads, fewer round trips, team autonomy | More services to run, monitor and secure |
| Composition in the BFF | One client round trip; parallel internal calls | BFF latency is the slowest required dependency |
| Partial responses | Screens survive optional failures | Clients must handle missing sections |
| Logic in the BFF | Fast client-specific changes | Duplication and drift between BFFs if the logic is shared |
| GraphQL instead of BFFs | Clients choose fields themselves | Query cost control, caching and schema governance |
Alternatives
- One general-purpose API (behind an API gateway): simplest when clients are similar.
- Gateway aggregation: composition in a shared gateway; fine for a few routes, but it couples client teams to one component.
- GraphQL or federation: one schema, clients select fields; resolvers do the composition.
- Server-driven UI: the backend sends screen layouts, so new screens need less client release work; a heavier commitment.
Failure modes
- Duplicated business logic: the same rule implemented in two BFFs drifts apart and clients show different results.
- BFF sprawl: one BFF per device or per screen; the number of services grows faster than the teams that can own them.
- Fan-out latency: a screen waits for its slowest dependency; without timeouts on optional calls, one slow service slows every screen.
- Hidden coupling: BFFs that call each other, or that depend on internal service details, break when services change.
- Old mobile versions: removing a BFF field breaks installed apps that still use it.
In production
Keep BFFs thin and stateless; scale them horizontally like any service. Give each call a timeout and decide per screen which calls are required and which are optional. Propagate trace context through the BFF so a slow screen can be traced to the service behind it. Track app versions in requests and keep old contracts until usage drops. Put shared rules in the owning services, and review BFFs for logic that has crept in.
Common misconceptions
- "A BFF replaces the API gateway." Usually it sits behind one; edge concerns stay shared.
- "One BFF per device." One per distinct experience; similar clients share one.
- "BFFs make the system simpler." They make clients simpler and teams faster, at the cost of more services.
- "Aggregation is always faster." Only when it removes round trips on a slow link; inside a fast network an extra hop just adds latency.
Interview angle
Bring up BFFs when a design has very different clients (mobile and web, or public partners) and the question is how to serve them: explain composition, payload shaping, team ownership and failure isolation, and place the BFFs behind the edge gateway. Expect probing on duplication (keep rules in services), latency (parallel calls, timeouts, partial responses), and when a single API or GraphQL would be enough.
Model assumptions
Most of this lesson is a scripted illustration: requests and responses are scripted packets, not simulated traffic, because the engine does not model payload sizes. A response's travel time includes an illustrative transfer time: the web app is 20 ms away on broadband; the mobile app is 60 ms away on a link of roughly 1.5 Mbit/s, so 48 KB adds about 256 ms and 9 KB about 48 ms. Services answer in about 15 ms; internal hops take 2 ms. The isolation and partial-response steps and the sandbox run simulated traffic (Poisson arrivals, 100 web and 150 mobile requests per second); there each BFF calls the three services in parallel and answers when all three have succeeded. In the partial-response step the Mobile BFF answers as soon as any 2 of its 3 calls have succeeded: the model counts answers rather than naming Catalog as the optional call, and it has no per-call timeouts. Numbers show behaviour and orders of magnitude only.