Backends for Frontends
Give each kind of client, such as web, mobile or partners, its own thin backend that shapes data exactly for that client.
Description
A single general-purpose API tends to fit no client well. The mobile app wants small payloads and few round trips, the web app wants rich pages, partners want stable, versioned resources. Every compromise lands on all of them.
With BFF, each frontend gets its own backend, usually owned by the same team as the frontend. A BFF calls the shared domain services and aggregates and reshapes their data for its one client. The domain services stay generic; client-specific logic lives in the BFF.
System design
Backends for Frontends system design diagram
- Web app (client).
- Mobile app (client).
- Web BFF (service): rich pages.
- Mobile BFF (service): one call per screen.
- Orders service (service).
- Catalog service (service).
- Step 1: Web app → Web BFF: GET /order-page.
- Step 2: Web BFF → Orders service: full order.
- Step 3: Mobile app → Mobile BFF: GET /home.
- Step 4: Mobile BFF → Orders service: last 3 orders.
- Step 5: Mobile BFF → Catalog service: deals, small images.
- The web app asks its own BFF for everything on the order page.
- The web BFF fetches the full order and shapes a rich response for the desktop layout.
- The mobile app asks its BFF for the home screen in a single call.
- The mobile BFF fetches only the last three orders…
- …plus today's deals with small images, and returns one compact payload for a slow network.
- AWS
- One Lambda- or ECS-based service per frontend behind API Gateway; AppSync for GraphQL BFFs.
- Azure
- Functions or Container Apps per frontend behind API Management.
- Google Cloud
- Cloud Run service per frontend behind API Gateway or Apigee.
When to use it
Use it when
- Clients need clearly different data shapes, payload sizes or call patterns.
- Separate teams own different frontends and want to move independently.
- A mobile app needs one call per screen instead of many chatty calls over a slow network.
Avoid it when
- There's one client, or all clients want the same data. One API is enough.
- You lack the people to run several backends. Each BFF is a service to deploy, monitor and secure.
- A flexible query layer such as GraphQL already lets each client ask for exactly what it needs.
Pitfalls
- Duplicated logic across BFFs, such as pricing rules. Shared business logic belongs in the domain services.
- BFFs that become full services with their own databases and rules. Keep them thin: aggregate, reshape, cache.
- One BFF per screen or per developer. One per type of client experience is the usual grain.
Alternatives
API Gateway
Choose it when one shared entry point with routing and policies is enough for all clients.
GraphQL
Choose it when clients differ mainly in which fields they need; one schema lets each query its own shape.
One general API
Choose it when clients are similar and a single team owns everything.