A made-up food-delivery company in Bengaluru has an Android app, an iOS app, a web dashboard for restaurant owners, and about a dozen backend services: restaurants, menus, orders, payments, delivery tracking, offers, and so on. Follow the team through three bad weeks and you will meet both patterns, in the order they are usually discovered.
Week one: every client talks to every service
At first the mobile app calls the services directly. Then the security review lands. Each service validates login tokens its own way. Rate limiting exists in two services and not in the rest. The app has twelve hostnames baked in, and when the team splits the orders service in two, the old app versions that cannot be force-updated start failing.
The fix is an API gateway: a single entry point in front of all services. Clients know one address. The gateway handles what is common to every request: authenticating the token, applying rate limits, terminating TLS, routing “/orders” to the orders service, logging, perhaps caching or request size limits. Kong, NGINX, AWS API Gateway, Azure API Management and Apigee are all examples. The gateway is deliberately generic; it should not know what a “restaurant” is.
Rerouting becomes a configuration change. Old app versions keep hitting the same public path while the team reshuffles services behind it.
Week two: the home screen needs seven calls
The gateway fixed routing but not shape. The mobile home screen shows nearby restaurants, active offers, the user’s current order status, reorder suggestions and a wallet balance. That is seven calls to seven services, over a patchy 4G connection in a lift. Each response also carries fields the phone never uses, because the services were designed for other consumers.
Someone suggests adding “aggregation” to the gateway. Resist it, because the gateway is shared infrastructure and will turn into a dumping ground for client-specific logic that every team now needs to edit and deploy together. The pattern that fits is a Backend-for-Frontend (BFF): a small server owned by the team that owns the client, existing only to serve that client. The mobile BFF exposes one endpoint for the home screen, calls the seven services in parallel, trims and combines the results, and returns exactly the JSON the app needs.
Week three: the web dashboard wants something different
Restaurant owners on a desktop want large tables, bulk menu edits, CSV exports and long-lived sessions. Their needs differ from the phone app’s: more data per call, different pagination, different permissions. Forcing both clients through one “general purpose” API produces endpoints that are too chatty for one and too fat for the other. So the dashboard gets its own BFF. The term itself, popularised by Sam Newman, makes the point: one backend per kind of frontend, not one for all.
How the two fit together
A common arrangement is: client, then gateway, then the relevant BFF, then internal services. The gateway deals with the edge concerns once. Each BFF deals with composition and presentation for its client. Sometimes the layers collapse: in a small system, one BFF directly exposed with auth handled by a cloud load balancer is enough, and some gateway products let you write light transformations. Treat the diagram as a menu, not a mandate.
| API gateway | Backend-for-Frontend | |
|---|---|---|
| Serves | All clients | One kind of client |
| Typical work | Auth, routing, rate limits, TLS | Aggregation, field trimming, client-specific formats |
| Owned by | Platform team | The frontend’s team |
| Business logic | Should have none | Presentation logic only |
What goes wrong
BFFs tempt teams to put real business rules there (“a discount only applies if…”). Then the Android BFF and the web BFF disagree, and customers see different prices. Rules belong in the domain services; the BFF only arranges and reshapes what they return.
The gateway can become a single point of failure and a bottleneck. Run several instances, keep its configuration in version control, and be strict about what logic is allowed in it. A gateway full of custom scripts is a monolith in disguise that nobody dares to touch.
Each BFF is another service to deploy, monitor and secure. Two BFFs that are ninety per cent identical probably should be one service. A BFF also adds a network hop, so fan-out calls should run in parallel and carry timeouts; one slow downstream service should not freeze the whole home screen. Return partial data when you can: show the page without offers rather than no page.
GraphQL is sometimes offered as a way to avoid BFFs, letting each client ask for exactly what it needs. It can work, but then someone still has to run and secure that GraphQL layer, and it is, in effect, one shared BFF with a query language on top.
Figures and names in the examples are illustrative.
Leave a Reply