Architecture & BFFAcronym: BFF

Backend for Frontend (BFF)

Direct Definition

Backend for Frontend (BFF) is an architectural pattern where a dedicated gateway layer is created for a specific frontend client (e.g., iOS, Android, React). Instead of clients calling multiple generic backend APIs, the edge BFF aggregates upstream calls, injects credentials, and strips unneeded payload fields before transmission.

Technical Architecture & Deep-Dive

The Backend for Frontend (BFF) pattern was popularized by SoundCloud and Sam Newman to solve the friction between frontend requirements and monolithic or microservice API outputs. Modern mobile apps and web frontends require distinct response shapes, authentication methods, and payload constraints.

Without a BFF, frontends must either make multiple sequential upstream HTTP requests (causing slow page loads and battery drain) or backends must expose bloated, generic endpoints that overfetch data. Running a BFF directly on globally distributed edge networks (like Cloudflare Workers) delivers the benefits of API aggregation and payload slimming with sub-10ms latency and zero server maintenance.

Key Architectural Benefits

Reduces mobile network roundtrips by consolidating multiple upstream APIs into a single request.
Prevents frontend overfetching by stripping 80%+ of unused JSON properties at the edge.
Shields proprietary upstream API keys and credentials from client-side reverse engineering.
Enables independent frontend and backend iteration without breaking changes.

Edge BFF Pipeline Pattern

typescript
// Edge BFF consolidating User Profile + Billing Status in parallel
const [userProfile, billing] = await Promise.all([
  fetch('https://api.internal.com/users/99', { headers: { Authorization: `Bearer ${SECRET_KEY}` } }),
  fetch('https://api.stripe.com/v1/customers/cus_99', { headers: { Authorization: `Bearer ${STRIPE_KEY}` } })
]);

// Return tailored, slimmed JSON exclusively for mobile client
return Response.json({
  id: userProfile.id,
  name: userProfile.displayName,
  plan: billing.subscriptions.data[0].plan.id,
  status: billing.subscriptions.data[0].status
});
REALCOMPOSER EDGE WORKSPACE

Build an Edge BFF in 2 Minutes

Compose upstream APIs, inject secrets safely, and deploy a global BFF endpoint with zero Docker containers.

LAUNCH TOOL

Frequently Asked Questions

Q:What is the main difference between a BFF and a standard API Gateway?

A general API Gateway serves all clients with common routing, rate limiting, and authentication. A BFF (Backend for Frontend) is tightly coupled to a specific user experience (e.g., iOS mobile app vs. desktop web), shaping and aggregating data tailored strictly to that interface.

Q:Why run a BFF at the edge instead of in Node.js or Express?

Running a BFF at the edge (on Cloudflare Workers V8 isolates) eliminates cold starts, removes Docker server management, and places the API aggregation layer within 10ms of global end users.

Q:Can a BFF handle parallel upstream requests?

Yes. Upstream fan-out allows the edge BFF to execute multiple HTTP subrequests concurrently via Promise.all, reducing overall latency to the duration of the slowest single upstream call.

Related Architecture Concepts

Ready-to-Use Edge Recipes