What is a backend-for-frontend (BFF), and when does a frontend need one?
IntermediateDesign patterns and architecture interview questionBy UIRound, updated 23 November 2026
Short answer
A backend-for-frontend (BFF) is a thin server-side layer built for one client, such as the web app or the mobile app, and usually owned by that client's team. The browser makes one request per screen; the BFF calls the domain services, merges and trims their responses into exactly what the screen renders, and often holds the user's tokens behind a session cookie. You need one when a screen depends on many services or on credentials the browser should not hold.
The problem it solves
Picture a product page that needs data from catalogue, pricing, inventory, reviews, recommendations and the user's wishlist. Called directly from the browser, that is six requests, each with its own latency, auth, error format and CORS setup. Some of them depend on each other, so they turn into a waterfall. Each service returns its full domain model, so the browser downloads fields it never shows. And every service needs a token the browser has to store.
The services are designed around business domains. The screen is designed around what the user sees. A BFF is the translation layer between the two, and because it is built for one client, it can be shaped exactly for that client.
Browser ── one request, session cookie ──▶ Web BFF
│ parallel calls, timeouts, tokens
┌────────────┬─────────┼──────────┬─────────────┐
▼ ▼ ▼ ▼ ▼
Catalogue Pricing Inventory Reviews RecommendationsThe name comes from Sam Newman's write-up of the pattern, based on work at SoundCloud, where separate BFFs served the web and mobile apps.
What a BFF does
- Aggregates. It calls services in parallel, close to them on a fast network, and returns one response. The browser pays one round trip instead of several, which matters most on mobile networks.
- Shapes the payload. It returns the fields the screen uses, already formatted: a display price instead of a pricing model, one image URL instead of every rendition. Responses get smaller and the client gets simpler.
- Handles partial failure. If reviews time out, it returns the page without them and a flag the UI can use, instead of failing the whole screen.
- Owns auth and sessions. The BFF completes the OAuth flow, keeps access and refresh tokens server-side and gives the browser an
HttpOnlysession cookie. RFC 10017, the IETF guidance on OAuth for browser-based apps, ranks this as the strongest of its architectures, because no token is ever reachable from page script. See access token vs refresh token for the token side. - Normalises errors. Each service's error format becomes one shape the client can act on.
- Removes CORS. Served from the same origin as the app, the browser talks to one same-origin API.
A small web-standard handler shows the core of it:
async function productPage(request: Request, productId: string): Promise<Response> {
const session = await getSession(request); // looks up the session cookie server-side
if (!session) return new Response(null, { status: 401 });
const call = (url: string, ms: number) =>
fetch(url, { headers: { Authorization: `Bearer ${session.accessToken}` }, signal: AbortSignal.timeout(ms) })
.then((r) => (r.ok ? r.json() : Promise.reject(new Error(`${url}: ${r.status}`))));
const [product, price, reviews] = await Promise.allSettled([
call(`${CATALOGUE}/products/${productId}`, 800),
call(`${PRICING}/prices/${productId}?region=${session.region}`, 500),
call(`${REVIEWS}/summary/${productId}`, 300), // nice to have: short timeout
]);
if (product.status === "rejected") return Response.json({ error: "product_unavailable" }, { status: 502 });
return Response.json({
id: product.value.id,
title: product.value.title,
image: product.value.images[0]?.url ?? null,
price: price.status === "fulfilled" ? price.value.display : null, // the UI shows "price unavailable"
rating: reviews.status === "fulfilled" ? reviews.value.average : null,
});
}The required call fails the request; optional calls degrade to null. That decision lives in one place, owned by the team that knows what the screen can live without.
BFF vs API gateway vs GraphQL
These get confused because they all sit between the client and the services.
| API gateway | BFF | GraphQL server | |
|---|---|---|---|
| Serves | All clients | One client or experience | Any client that writes queries |
| Main job | Cross-cutting concerns: routing, TLS, rate limits, auth checks | Aggregation and shaping for specific screens | A typed graph that clients query flexibly |
| Knows about screens | No | Yes | No; the client's query decides the shape |
| Owned by | Platform team | The client's team | Often a platform or API team |
They are not exclusive. A common setup has a gateway at the edge, BFFs behind it per client, and domain services behind those. A GraphQL server can itself act as a shared BFF: it aggregates and lets each client select only the fields it needs, so you may not need one BFF per client. What GraphQL does not give you for free is screen-specific logic such as fallbacks, formatting and which failures are fatal. See REST vs GraphQL for that trade-off, and forward vs reverse proxy for where a gateway sits.
Frameworks that render on the server blur the line further. Server components, route loaders and server actions already run on a server you own, next to the services, so they can play the BFF role without a separate deployment.
When a frontend needs one
Reach for a BFF when several of these are true:
- A key screen needs data from three or more services, or has dependent calls that create a waterfall.
- Responses are much larger than what the screen uses, and mobile users pay for it.
- Web and mobile need different shapes, and a shared API keeps growing optional parameters to satisfy both.
- Tokens should not live in the browser: banking, health, admin consoles, anything where XSS stealing a token is unacceptable.
- The frontend team is blocked waiting for backend teams to add fields or endpoints for each UI change.
Skip it when one well-designed API already serves the screens, or when the app is small enough that another service is more work than it saves.
What it costs
- Another service to run. Deployments, monitoring, scaling, on-call. If the BFF is down, the whole client is down.
- An extra hop. Usually a net win because it replaces several browser round trips, but a BFF that calls services one after another adds latency instead of removing it.
- Duplication. Separate web and mobile BFFs often reimplement the same aggregation. Share libraries, or accept a single BFF for similar clients.
- Logic creep. Business rules such as pricing, permissions and stock decisions belong in the domain services. A BFF that starts deciding them becomes a second, unowned backend. Keep it to composition, shaping and session handling.
- Caching gets harder. Merged, per-user responses cache less well than public service responses. Cache the public parts inside the BFF and keep the per-user parts small.
The client-server API design guide places the BFF alongside pagination, errors and versioning, and a BFF for a page that calls nine services is a full practice prompt.
Follow-up questions interviewers ask
Should there be one BFF per client or one per team?
The original advice is one per user experience: web, iOS and Android may share one if their screens are similar, and a very different client such as a TV app gets its own. Splitting by backend team instead tends to recreate the service boundaries the BFF was meant to hide.
How does a BFF help security?
Tokens stay on the server, the browser holds only an HttpOnly, Secure, SameSite session cookie, and the BFF can enforce per-user access before data leaves the network. You still need CSRF protection for cookie-authenticated writes. The SPA authentication design compares this with in-browser token storage.
How do you stop a slow service from slowing the whole page?
Call services in parallel, give each a timeout matched to its importance, return partial data with clear flags, and stream or defer the slow parts if the framework supports it. A financial dashboard with partial API failures works through this.
Is a BFF the same as micro-frontends?
No. Micro-frontends split the UI between teams; a BFF is a server layer for one client. A micro-frontend team may own a small BFF for its part of the page, which keeps the vertical slice independent.
Sources
Practise it in code
Interviewers rarely stop at the definition. These questions open in an editor with tests.
- Design a backend-for-frontend (BFF) for a page that calls nine servicesHard45 min
- Design an internal financial records dashboard: a summary, a searchable history table, partial API failures and accessible errorsHard60 min
- Design a personal finance dashboard like INDmoney: account aggregation, charts, privacy and stale dataHard55 min
- Design SPA authentication: OAuth PKCE, token storage, refresh rotation and multi-tab refreshHard60 min
- Design authentication and authorization for an internal admin consoleHard45 min
- Design an e-commerce product detail page: variants, image gallery and zoom, reviews, recommendations, fresh price and stock, SEO and Core Web VitalsHard60 min