Skip to content

Backend for Frontend (BFF): when to use it, types and GraphQL

What a BFF is, where it came from, the five types in use today and when not to build one. With RFC 10017, Next.js, Astro and the GraphQL question.

Ramon Gomes 18 min read Level: Advanced

Also available in: Español, Français, Português

Series Front-end for a news portal Part 4 of 7

In a Senior Full-Stack React/Next job posting I went through recently, "BFF" showed up on the same line as "Next.js" and "GraphQL". The three words travel together and get mixed up all the time: some people call any Route Handler a BFF, some think GraphQL retired the pattern, and some spin up an extra Node service because the diagram next door had one.

The personal CRM I use every day has no BFF. My portfolio has one, a read-only one, that I never had to write. And the booking app I maintain in React Native splits commands from reads in a way that looks like a BFF without being one. Below are the origin, the types, the comparisons, what the new OAuth RFC changed and when I wouldn't build one.

Where the Name Came from

Phil Calçado tells how, at SoundCloud, the web and the apps consumed the same public API, with generic, thin endpoints: lots of calls per screen over slow mobile networks, app-only features that were impossible to expose, and every change negotiated with every client. The way out was to give each application its own backend. The name "Back-end for Front-end" was coined by Nick Fisher, the web tech lead, and the company ended up running about five BFFs in production (Calçado, 2015).

Two months later, Sam Newman wrote the piece that spread the idea: the BFF is "tightly focused on a single UI, and just that UI" (Newman, 2015). One BFF per experience, owned by the team behind that interface, so the number of BFFs ends up following the team structure. The Thoughtworks Technology Radar placed the pattern in Trial in 2015 and 2016 (Thoughtworks).

What Problem a BFF Solves

Think of two ways to serve lunch. At a buffet, all the food is laid out and each person builds their own plate. It works for a crowd with similar appetites. With a waiter, the kitchen is the same, but the plate arrives made up for that table: a small, cut-up portion for the kid, a full plate for the adult.

Line of people seen from behind at a pay-by-weight buffet, serving themselves from stainless steel trays, one of them reaching out with a plate already full
A generic API is a buffet: everything is there, but every client does the work of building the plate, and the phone always ends up carrying more than it needs.

The generic API is the buffet. To show an order, the app calls /orders/10482, /customers/77, /products?ids=... and /deliveries/10482, then throws away half the fields. On a laptop with fiber nobody notices; on a phone over 4G that's four round trips.

The BFF is the waiter. It sits on the server, close to the services, makes the calls in parallel and returns only what the screen uses. Newman insists on degrading instead of failing: if the inventory service is down, only the stock indicator disappears and the page stays up.

Waiter seen from behind at a kitchen pass, plating two different dishes from the same pots, a kids' plate with a small portion and a full one, with blank order tickets on the rail
Same kitchen, different plates. The BFF is the waiter who knows table 4 has a kid and table 7 is in a hurry.

Microsoft sums it up: a separate backend service for each interface, instead of one general-purpose backend (Azure Architecture Center, 2025).

The Types of BFF in 2026

When someone says "BFF" in a meeting, it's worth asking which of these they mean:

  • Per experience or client. The classic: one for web, one for iOS, one for TV. Newman recommends thinking about it from the start when there's a mobile app or third parties, and says web alone rarely needs one.
  • Per team. The split follows the organization. If the same team builds iOS and Android, one BFF for both is enough; that's how SoundCloud did it.
  • Security. The reason is where the token lives. The BFF becomes the confidential OAuth client, keeps the tokens on the server and hands the browser only an HttpOnly cookie. Curity calls its variant the token handler: an "OAuth Agent" issues the cookie and an "OAuth Proxy" in the API gateway swaps the cookie for a token, while the SPA still ships from the CDNNetwork of servers spread around the world that keeps copies of files and pages close to users, serving them faster and offloading the origin server. (Curity, 2024).
  • GraphQL as a BFF. A GraphQL server owned by one front end, with resolvers that stitch together legacy REST. Condé Nast called it "a low-stakes way to introduce GraphQL to an organization" (InfoQ, 2020); Alura has a course (in Portuguese) that builds one in NestJS with Apollo (Alura).
  • Framework-embedded. The one growing fastest and showing up least in articles. Next.js has an official guide called "Backend for Frontend", updated on November 6, 2026, built on Route Handlers and proxy (Next.js, 2026). In Astro, a page with prerender = false fetches data on the server before sending the HTML: that's already a read BFF. For the rest of that conversation, see which rendering strategy to use.

BFF, API Gateway, GraphQL Federation and tRPC

All four sit in the same spot on the diagram, between the client and the services. Hence the confusion.

Two-part diagram: without a BFF, the phone and the browser call the orders, customers and deliveries services directly, several calls each; with a BFF, each client calls its own BFF once, and the BFF talks to the three services in parallel
Without a BFF, the client builds the plate. With a BFF, the client places one order and gets the finished screen.
BFF API gateway GraphQL gateway / federation tRPC
Serves one interface every client every client, through one graph one TypeScript front end from the same team
Owner the interface team platform or infra domain teams (subgraphs) + platform the full-stack team
Good at aggregating, trimming, adapting, holding the session authentication, rate limiting, routing, caching the client picks the fields; shared types end-to-end types without code generation
Business logic shouldn't have any must not have any in the subgraphs wherever the team wants (risk)
When it hurts duplication across BFFs turns into an aggregation monolith bloated schema, expensive queries a second client shows up that isn't TS

Gateway and BFF don't compete, they stack. Sensedia (in Portuguese) defines the gateway as a server that acts as the single entry point for communication between external clients and internal services, handling routing, authentication and request limits (Sensedia, 2026). In Microsoft's example, an API Management instance validates JWTs and caches in front of two BFFs; cross-cutting authorization and rate limiting live in the gateway, and the BFF keeps only the experience logic. tRPC, designed for TypeScript monoreposSingle repository that holds several related projects or packages, such as apps and shared libraries, with common versioning and tooling. (tRPC), never uses the word BFF, but in practice it is one: only your front end calls it, with an implicit contract, until the day a Swift app needs the same API. And MCPOpen protocol that standardizes how AI apps connect to external tools and data: a server exposes actions and the agent discovers and calls them., which also sits in front of an API, serves an AI agentProgram that uses a language model to choose actions, call tools and repeat the loop until a task is done, with little human input., not a screen; the difference is covered in MCP or API.

The Security BFF: What RFC 10017 Changed

For years, "keep the token on the server" was advice from identity vendors. In August 2026, the draft-ietf-oauth-browser-based-apps draft became RFC 10017, published as BCP 212 (RFC Editor, 2026). A lot of writing still calls it "the draft". It isn't anymore.

Section 6 lists three architectures "in decreasing order of security":

  1. Backend for Frontend. A confidential client that holds the tokens and proxies everything: "there are no tokens available to extract from the browser". Cookies must be HttpOnly and Secure. Strongly recommended for business applications, sensitive applications or anything with personal data.
  2. Token-mediating backend. The backend obtains the token but hands it to JavaScript. The access token can still be stolen, and the text suggests evaluating a full BFF first.
  3. Browser-based OAuth client. The SPA as a public client, with the token in the browser.

It matters now because silent renew through an iframe depended on third-party cookies, and browsers closed that door. Duende, which sells a BFF library (take it with that grain of salt), put it this way in 2026: for authentication, "there is no replacement" (Duende, 2026).

A BFF doesn't save you from everything. "A cookie-based session does not make the SPA immune to attacks", Auth0 reminds us: an XSS can still fire calls through the BFF while the tab is open, and the cookie brings CSRF back (Auth0, 2024). The gain is that the token never leaves the server. The bigger picture on sessions, JWT and OAuth is in types of authentication.

When the Framework Already Is the BFF

In Next.js, the simplest BFF is a Route Handler that forwards to an internal service. The official guide insists on two precautions: forward only the headers you need (copying everything leaks Cookie and Authorization to places they shouldn't go) and take the destination from a fixed map, so that "a caller cannot point the request, or its token, at another destination", which is the defense against SSRF (Next.js, 2026). An example along those lines:

ts
// app/api/dashboard/[resource]/route.ts
import { cookies } from 'next/headers';
import { sessionToken } from '@/server/session'; // tokens stay on the server

const ENDPOINTS = {
  orders: 'http://orders.internal/v1/orders',
  profile: 'http://accounts.internal/v1/me',
} as const;

export async function GET(
  _req: Request,
  { params }: { params: Promise<{ resource: string }> },
) {
  const { resource } = await params;
  const target = ENDPOINTS[resource as keyof typeof ENDPOINTS];
  if (!target) return new Response('Not found', { status: 404 });

  const session = (await cookies()).get('__Host-session')?.value;
  const token = session ? await sessionToken(session) : null;
  if (!token) return new Response('Unauthorized', { status: 401 });

  const response = await fetch(target, {
    headers: { Authorization: `Bearer ${token}` }, // only what the service needs
    cache: 'no-store',
  });
  return new Response(response.body, {
    status: response.status,
    headers: {
      'Content-Type': response.headers.get('Content-Type') ?? 'application/json',
      'Cache-Control': 'private, no-store',
    },
  });
}

The warnings in the guide that separate people who read it from people who just used it:

  • "Next.js backend capabilities are not a full backend replacement." Heavy domain rules belong in a real service.
  • Route Handlers "are public HTTP endpoints. Any client can access them."
  • A Server Component shouldn't fetch data from its own Route Handler: that's an extra round trip. Call the function directly.
  • Server Actions "are queued": using an Action for reads serializes the calls.
  • Cache-Control: public on the CDN skips the credential check.

The data security guide fills in the rest: for a new project, a Data Access Layer with server-only that authorizes and returns a minimal DTO; and every Server Action, reachable by a direct POST, re-authenticates and re-authorizes (Next.js, 2026).

If I Use GraphQL, Do I Need a BFF?

Serious sources disagree. I found four positions:

Position Who holds it The argument
GraphQL makes the BFF unnecessary Microsoft Azure; Netflix (streaming) With resolvers specific to each front end, a BFF "might not add value" (Azure). At Netflix, GraphQL "is supposed to do the job of the BFF" (InfoQ, 2021)
GraphQL is the BFF Zalando; Condé Nast Zalando replaced per-client BFFs with a Unified BFF in GraphQL, under the principle "No Business Logic" (Zalando, 2021)
The BFF uses GraphQL inside, services stay REST Thoughtworks Radar "GraphQL for server-side resource aggregation" in Trial in 2020, with a warning against GraphQL between servers (Thoughtworks, 2020)
One federated graph instead of many BFFs Apollo; Netflix Studio "One unified graph, instead of multiple graphs created by each team" (Principled GraphQL)

Netflix shows the pendulum swing: in Studio, the aggregation gateway "has effectively become a monolith", and the way out was federation, with domain services owning the logic (InfoQ, 2020); today there are 150 subgraphs (Apollo, 2024). Zalando moved away from per-use-case BFFs because they created duplicated effort and even different delivery estimates between the app and desktop.

My recommendation, which is my own reading of the sources: GraphQL solves the shaping BFF. If the problem was "each screen asks for different fields", a graph with persisted queries solves it without a new service, because the gateway only runs the operations registered at build time, one contract per client. At Apollo that's safelisting, on the Enterprise plan (Apollo); in Hive Gateway it's open (The Guild). The security BFF, on the other hand, stays: the graph doesn't hold a session cookie or act as a confidential OAuth client. With Next or Astro, whatever does that is already on the server. To try out queries, the GraphQL guide and Hoppscotch are enough.

Three Cases of Mine: No BFF, a Read BFF, and Commands Split from Reads

Personal CRM: No BFF, and That's the Right Call

My CRM is Next 16 on the front end and FastAPI on the back end, on the same domain: Traefik sends /api to FastAPI and everything else to Next. The browser calls FastAPI directly, with a typed client generated from OpenAPI and credentials: "include". The session is an HttpOnly __Host-rahcrm_session cookie; next to it goes a CSRF cookie that is readable on purpose, which the front end sends back in the X-CSRF-Token header on every write.

No token ever passes through JavaScript, which is what RFC 10017 asks for, and there's no BFF service. It isn't needed: front end and API belong to the same team and the same domain, and FastAPI already is the session backend. Next's proxy.ts only handles CSP and redirects to the login page when there's no cookie; there isn't a single route.ts. A BFF there would be one more network hop to forward the same request. I described how I built this CRM in build your own CRM with AI.

The only mini-BFF lives inside the API: the pass-through to the password vault, with locked-down routes, destination validated against SSRF and no body or token in the logs. Same principle as the ENDPOINTS map in the Next guide.

Portfolio: Astro SSR as a Read BFF

This site runs Astro with a separate Node API. The page you're reading has prerender = false: the Astro server fetches the article from the API over Docker's internal network, without going out through the public TLS proxy and back, and returns 404 for anything missing, still a draft or when the API is down. I didn't write a BFF; SSR gave me one.

Where I don't use a security BFF: the admin panel keeps the access token in memory and the refresh token in an HttpOnly cookie. On the RFC 10017 scale that's third place, mitigated. For a panel with a single user, I accepted the risk; if more people get access, it becomes a server-side session.

ManiVez: Functions for Commands, Firestore for Reads

In ManiVez, a booking app in React Native with Firebase, the app reads Firestore directly through the SDK, with real-time onSnapshot. Writes that carry business rules go through 64 onCall Functions with App Check, and the security rules forbid the client from writing to sensitive collections (allow write: if false). It's not a classic BFF, it's a pocket-sized CQRS. And the RFC doesn't even apply: it covers browser apps.

When to Use It and When Not to

Five-step decision tree: more than one interface with different needs, per-experience BFF; browser SPA with OAuth and sensitive data, security BFF; already running Next or Astro on the server, use the framework as the BFF; already have GraphQL with per-screen resolvers, the graph does the job; one interface on the same domain as the API with a cookie session, no BFF needed
Start at the top. If no question matched, the answer is don't build one.

Ana Neri asks in her title (in Portuguese) "BFF é Over-Engineering?" and answers that the biggest challenge lies in the complexity it creates between teams (Neri, 2025). I agree: the cost is rarely the code, it's one more service to deploy, monitor and be on call for.

Pitfalls

  • The BFF turning into a business-logic monolith. Only experience logic goes in the BFF. A price calculated in the app's BFF and again in the web one becomes a mismatched-price bug, like Zalando's delivery estimate.
  • Duplication with no owner. It will happen; Azure calls it a "probable outcome". Newman waits for the pattern to show up a third time before abstracting, and SoundCloud pulled the repeated profile code into a UserProfileService, a domain service, not a shared library.
  • Open proxy. Forwarding any path or every header turns into SSRF and a leaked Authorization. Keep destinations in a fixed map.
  • Caching in the wrong place. An authenticated response with Cache-Control: public serves one person's data to someone else.
  • Heavy processing in the BFF. Heavy processing doesn't belong in the BFF, as Adriano Mota puts it (in Portuguese) (Mota, 2022). The BFF is the waiter, not the cook.
  • Forgotten CSRF. Swapping localStorage for a cookie brings CSRF back: SameSite, the __Host- prefix and a CSRF token on writes.

Frequently Asked Questions

What's the difference between a BFF and an API gateway?

An API gateway serves every client and handles cross-cutting concerns such as authentication, rate limiting and routing. A BFF serves a single interface and adapts the data for it. The two usually live together, with the gateway in front of the BFFs.

Do I need one BFF per platform?

Not necessarily. Sam Newman suggests one per user experience, and the number tends to follow the teams. If the same team builds iOS and Android with the same screens, one BFF for both may be enough.

Does GraphQL federation replace the BFF?

It replaces the shaping BFF, when the graph has resolvers designed around the screens and persisted queries limit what each client can run. It doesn't replace the security BFF, because the graph doesn't hold a session or act as a confidential OAuth client.

What does RFC 10017 say about storing tokens in the browser?

It ranks three architectures from most to least secure: BFF, token-mediating backend and the SPA as a public client. With a BFF, no token stays in the browser, only an HttpOnly, Secure cookie. For applications with personal or business data, the recommendation is the BFF.

BFF or token handler for an SPA?

The token handler is a variant of the security BFF that keeps the SPA on the CDN and swaps the cookie for a token at the gateway. It makes sense when you already have an API gateway and don't want a server just for the front end.

What logic can live in the BFF?

Experience logic: combining calls, trimming fields, turning codes into on-screen text, paginating the way the interface wants and degrading when a service goes down. Business rules, such as pricing, domain permissions and inventory, stay in the services.

References

Source: https://ramongomessilva.com.br/blog/backend-for-frontend-pattern · Accessed on December 02, 2026

Share Share on LinkedIn Share on X
Cite this article

Ready-made reference, with today as the access date.

ABNT

Brazilian standard (NBR 6023). Use it in theses and academic papers submitted in Brazil.

GOMES, Ramon. Backend for Frontend (BFF): when to use it, types and GraphQL. Ramon Gomes, 19 nov. 2026. Disponível em: https://ramongomessilva.com.br/blog/backend-for-frontend-pattern. Acesso em: 2 dez. 2026.

APA

American Psychological Association style. Common in scientific papers and journals, especially in the social, behavioral and health sciences.

Gomes, R. (2026, November 19). Backend for Frontend (BFF): when to use it, types and GraphQL. Ramon Gomes. https://ramongomessilva.com.br/blog/backend-for-frontend-pattern

BibTeX

Format for LaTeX users (Overleaf, for example). Paste it into your .bib file or import it into Zotero or Mendeley.

@online{gomes2026backendforfrontend,
  author = {Gomes, Ramon},
  title = {{Backend for Frontend (BFF): when to use it, types and GraphQL}},
  organization = {Ramon Gomes},
  year = {2026},
  month = nov,
  date = {2026-11-19},
  url = {https://ramongomessilva.com.br/blog/backend-for-frontend-pattern},
  urldate = {2026-12-02}
}
Found a mistake?

Wrong fact, broken link, outdated information: tell me and I will fix it.

10 to 2,000 characters. If you can, point to the right source.

Only so I can reply. It never shows on any page of the site.

Written by

Ramon Gomes

Software Engineer

Full stack software engineer. I like taking a messy problem, listening to the people who live with it and shipping something that holds up day to day. These days I split my time between my own products, applied AI and client work.

Available for projects

Need Something Like This Built?

I build websites, systems, apps and AI automations, from design to deploy. Tell me what you need or see what I offer.

Related Articles