When a system has several clients, one shared API for everyone grows quickly: each client needs its own data in its own shape, and every change has to be made in the same code and agreed with a single team. The answer is a backend for frontend: a thin server-side layer between the client and the internal services, one for each type of client. It is usually maintained by the same team that builds the interface itself.
Why a client needs its own backend
- Fewer round trips: a mobile screen shows little data, while extra requests drain traffic and battery — a BFF returns the ready data in a single call.
- A format shaped for the client: the web version needs some fields and aggregates, the mobile one others; the response is tailored on the server rather than in each client’s code.
- Its own team: the interface and its BFF evolve within one team, without coordinating with the owners of the shared API, and client and server releases keep pace.
- Isolation: reworking the API for Android does not break the web and iOS versions — each backend has its own deployment cycle.
How it works
The main job of a BFF is aggregation. Example: a wish list in an online shop, where each item needs its name, price and stock level shown. The data lives in three services: the wish list stores the items, the catalogue has the names and prices, the warehouse the stock levels. The BFF receives a single request from the app, makes three calls — in parallel where possible — and stitches together one response. If the warehouse service is unavailable, it can return the list without stock levels: the client must be able to display such a partial response.
There can be several backends — one per type of client, as at REA, or one per interface type: at SoundCloud the listeners’ apps for iOS and Android worked with a single shared BFF. The rule of “one experience, one BFF”: if the scenarios of the platforms diverge, it is better to split them up, while a shared BFF for several teams is a road to bloated code.
How it differs from an API gateway
An API gateway is one for all clients and handles the common tasks: routing, authentication and rate limiting. A BFF, by contrast, is designed around a single client and knows its scenarios. Common perimeter tasks — access checks, request logging — can be kept above the BFF, in a layer such as Nginx, so that they are not duplicated in every backend, though an extra layer adds latency. In practice the two are combined: the gateway sits at the entrance, and backends for frontends work behind it. For a single web client with no complex aggregation a BFF is superfluous, and when substantial logic is duplicated across several BFFs it is moved down into a shared service.
The name “Backend for Frontend” was coined at SoundCloud: according to Phil Calçado, its author was Nick Fisher, tech lead of the web team. Phil Calçado described the approach in 2015, and Sam Newman, in the article “Pattern: Backends For Frontends”, analysed the experience of SoundCloud and REA.
Sources
the term is written from these pagesVerified 8 Nov