In service-oriented distributed architectures, the Backend for Frontend (BFF) pattern, initially popularized by Sam Newman, emerges as a response to the constant tension between two opposing needs:

  1. The backend's need to expose generic, cohesive services centered on the business domain.
  2. The frontend's need (web, mobile apps, kiosks, or B2B integrations) to consume compact, aggregated payloads optimized for a specific user interface or device.

Trying to meet both demands with a single "shared public API" layer usually leads to two classic problems: network overhead on mobile devices (over-fetching / under-fetching) or endpoints coupled to particular views that end up degrading the design of the core microservices.


1. The Problem: The Single General-Purpose API

Let's imagine a standard omnichannel flow (for example, the customer detail in checkout or CRM):

  • Mobile App: Needs to render quickly on unstable 4G/5G connections. It needs the customer's name, their points balance, and their last 3 orders. It wants a minimal payload (< 10 KB) in a single HTTP/2 call.
  • Desktop Web Portal: Has more bandwidth and screen space. It additionally needs the full billing history, saved tax addresses, and notification preferences.

What happens without a BFF?

  • "One microservice per view" strategy: The mobile client makes 4 or 5 chained calls (/users/{id}, /loyalty/{id}, /orders?limit=3, /discounts). This multiplies latency by the sum of the RTT (Round Trip Time) of each connection over mobile networks.
  • "Multipurpose monolithic endpoint" strategy: An endpoint is created in the central backend that returns everything. The mobile app discards 70% of the data received (over-fetching), needlessly consuming battery and data allowance.

2. Solution Topology: BFF + API Gateway

The BFF pattern introduces an intermediate layer where each user experience has its own consumption backend, ideally maintained by the same team that builds the client interface.

flowchart TD subgraph Clients ["Clients"] App["Mobile App (iOS / Android)"] Web["Web SPA (Desktop)"] Pos["Kiosk / POS"] end subgraph Edge ["Edge"] Gateway["API Gateway (e.g., Kong)"] end subgraph BFF_Layer ["BFF Layer"] BFF_Mobile["Mobile BFF (Node.js / Go)"] BFF_Web["Web BFF (Node.js / Go)"] end subgraph Core_Services ["Core Services"] S1["Customer Service"] S2["Loyalty / Points Service"] S3["Order Service"] end App --> Gateway Web --> Gateway Pos --> Gateway Gateway -->|/api/v1/mobile/*| BFF_Mobile Gateway -->|/api/v1/web/*| BFF_Web Gateway -->|/api/v1/pos/*| S3 BFF_Mobile --> S1 BFF_Mobile --> S2 BFF_Mobile --> S3 BFF_Web --> S1 BFF_Web --> S2 BFF_Web --> S3