Video in progress
What is the BFF (Backend for Frontend) pattern, and how does it differ from a regular API gateway?
A BFF is a separate backend layer for each client type (web, mobile), tailored to that client's needs. A gateway handles shared concerns (routing, auth, rate limiting), while a BFF handles assembling data and shaping it for the client.
📖 Answer
The problem starts like this: a mobile app calls 6 services for one screen, and on a slow network that is 3 seconds. The web app wants different fields. If you put all of it into a single gateway, it fills up with the logic of different clients and turns into a "monolith" that every team changes.
With BFFs:
mobile app → mobile-bff ─┐
web app → web-bff ─┼→ order / catalog / user services
partner API → gateway ─┘
mobile-bff exposes a single /home endpoint, calls the services in parallel inside, takes the fields it needs and returns a small response. Version support for mobile lives here too: old app versions stay in use for years, and the BFF serves them the old format.
Usually the BFF is owned by the team that writes the client, so when a screen changes they don't wait for the backend team.
Risks:
- if business logic leaks into the BFF, it lives in two places. A BFF should only assemble and format;
- BFFs multiply and code gets duplicated;
- one more network hop and one more thing to deploy.
For a small project with a single client, a BFF is overkill. It pays off when there are two or three kinds of clients and their needs differ seriously.
Sign up to mark studied questions and save your progress.