Backend for Frontend (BFF): API Shaped for a Specific Frontend

Medium•

Backend for Frontend (BFF) is a pattern where a dedicated backend layer is introduced for a specific frontend, such as web, mobile, or admin.

The goal is not to duplicate the entire backend. The goal is to give each frontend an API that matches its actual screens, request patterns, security model, and performance needs.

In practice, a BFF is most useful when frontend apps are becoming too aware of backend service topology and are doing too much client-side stitching.

Quick Decision Guide

Senior-Level Decision Guide:

- A BFF is a backend layer built for a specific frontend or client type. - Use it when frontend apps are doing too much orchestration, or when web/mobile/admin need different API shapes. - A BFF usually handles aggregation, response shaping, auth/session adaptation, and frontend-specific policies. - It can simplify clients and improve API fit, but it adds another layer to own and operate.

Interview framing: A BFF is an API layer designed around the needs of a particular frontend experience rather than exposing raw backend service boundaries directly to the client.

What is a BFF?

Definition

A Backend for Frontend (BFF) is a backend layer designed specifically for one frontend or one class of frontend clients.

Example:

Web App    → Web BFF    → Backend Services
Mobile App → Mobile BFF → Backend Services
Admin App  → Admin BFF  → Backend Services

Instead of every client calling many backend services directly, the frontend talks to a BFF that exposes APIs shaped for that frontend.

Short mental model

A BFF is:

•not the main domain backend
•not just a gateway rule
•yes an adaptation and orchestration layer for frontend needs

Why Teams Add a BFF

Practical Signals

Teams usually introduce a BFF when one or more of these problems show up:

1. One screen needs too many backend calls

The frontend must fetch and combine data from multiple services just to render one page.

2. Different clients need different API shapes

Web, mobile, and admin often do not want the same payload or the same number of requests.

3. Frontend code is doing too much backend stitching

The UI starts owning retry logic, merging responses, filtering fields, and translating backend models into UI models.

4. Shared APIs are slowing frontend work

Backend APIs are usually organized by domain ownership, but frontend development is organized by screens and user flows.

5. Auth/session logic leaks into every client

Token exchange, session enrichment, and permission-related details start getting repeated across apps.

Good interview answer

A team adds a BFF when direct frontend-to-service access starts creating too much coupling, too many requests, or too much client-side orchestration.

What a BFF Usually Handles

Common Responsibilities

A BFF often handles the following frontend-specific work:

Aggregation

Call multiple services and combine the results into one response.

Response shaping

Return exactly the fields and structure the UI needs instead of raw backend domain objects.

Orchestration

Control the sequence or parallelism of backend calls for a page or flow.

Auth/session adaptation

Keep some security-sensitive handling on the server side rather than pushing it into the client.

Client-specific policies

Examples:

•mobile gets smaller payloads
•admin gets extra metadata
•web gets richer data for larger layouts

Important boundary

A BFF should stay focused on frontend-oriented adaptation.

It should not slowly absorb unrelated business logic that really belongs in core backend services.

When to Use a BFF

Strong Use Cases

1. Web and mobile have different needs

Mobile often needs fewer requests and smaller responses, while web may want richer data.

2. Dashboard or homepage composition

A single page needs data from many services and the browser should not orchestrate all of it.

3. Frontend team needs faster iteration

A BFF can let a frontend team evolve its API contract without changing generic shared backend APIs for every client.

4. Security-sensitive public clients

You want to keep more auth/session handling server-side instead of exposing everything directly from the client.

5. Legacy backend abstraction

Underlying services are inconsistent, but you want a stable contract for the frontend.

Weak use cases

A BFF is often unnecessary when:

•there is only one simple frontend
•existing APIs already match UI needs well
•orchestration needs are minimal

Security Role

Why Security Comes Up in BFF Discussions

A BFF can act as a safer boundary between public clients and backend services.

Examples:

•session handled through server-side mechanisms
•backend tokens not exposed directly to the browser
•permission checks centralized closer to the server

Practical value

This reduces how much security-sensitive logic each frontend must implement by itself.

Important nuance

Security alone is not a reason to throw a BFF everywhere. But for SPAs, mobile apps, and multi-client systems, it is often one of the strongest supporting reasons.

Tradeoffs

Costs of Adding a BFF

1. More architecture to maintain

You now own another backend layer with its own deploy, observability, and failures.

2. More debugging paths

Problems can now come from the client, the BFF, or downstream services.

3. Risk of misplaced logic

If the BFF starts owning too much domain logic, it becomes a messy middle layer.

4. Possible duplication across BFFs

Some duplication is acceptable because web and mobile may genuinely need different behavior.

The real problem is not duplication by itself. The real problem is duplication without clear ownership or boundaries.

Interview framing

The tradeoff is simple: better frontend-specific APIs in exchange for another layer to build and operate.

BFF vs API Gateway

API Gateway

An API gateway is usually infrastructure-focused. It often handles:

•routing
•auth enforcement
•rate limiting
•logging
•traffic controls

BFF

A BFF is frontend-focused. It usually handles:

•aggregation
•response shaping
•frontend-specific orchestration
•client-specific API contracts

Easy distinction

•API Gateway = infrastructure entry point
•BFF = frontend experience layer

Some systems use both.

BFF vs GraphQL

GraphQL and BFF Are Not the Same Thing

GraphQL is a query language and execution model.

A BFF is an architectural pattern.

A BFF can expose REST or GraphQL.

Useful nuance

A GraphQL layer can behave like a BFF if it is designed around frontend needs and handles orchestration across services.

But GraphQL by itself does not automatically solve:

•auth/session adaptation
•client-specific policies
•server-side frontend orchestration decisions

Example Flow

Example: Product Page

Without a BFF, the frontend may call:

•/product/:id
•/inventory/:id
•/reviews/:id
•/recommendations/:id

Then the browser combines everything.

With a BFF, the frontend can call:

•/web/product-page/:id

And the BFF can return a UI-ready response such as:

{
  "product": { "id": "p1", "name": "Keyboard" },
  "inventory": { "inStock": true },
  "reviewsSummary": { "rating": 4.7, "count": 1280 },
  "recommendations": []
}

That API is much closer to what the screen actually needs.

Interview Scenarios

Scenario 1: Why not let the frontend call all services directly?

Because it increases coupling, request count, and client-side orchestration complexity.

Scenario 2: Why is BFF useful for mobile?

Because mobile often benefits from fewer requests, smaller responses, and more controlled server-side composition.

Scenario 3: Is BFF the same as an API gateway?

No. Gateway is usually infrastructure-oriented; BFF is frontend-oriented.

Scenario 4: Can GraphQL replace BFF?

Not always. GraphQL can help with flexible fetching, but BFF concerns like auth/session adaptation and frontend-specific orchestration may still remain.

Scenario 5: Best one-line answer

A BFF is a backend layer built specifically for a frontend so the frontend gets APIs shaped around its real UI and user-flow needs.

Key Takeaways

1A BFF is a backend layer designed for a specific frontend or client type.
2Teams usually add a BFF when clients are doing too much orchestration or when different frontends need different API contracts.
3A BFF commonly handles aggregation, response shaping, orchestration, and some auth/session adaptation.
4It is most valuable for multi-client systems such as web, mobile, and admin products.
5A BFF can simplify frontend code and reduce coupling to backend service boundaries.
6It adds another layer to own, monitor, and debug.
7Some duplication across BFFs can be acceptable when clients truly have different needs.
8A BFF is different from an API gateway.
9GraphQL can complement a BFF strategy but is not automatically the same thing.
10Not every product needs a BFF.