What Is a BFF, and Why Use One?
🎯 Introduction
An order details page needs the order total, the customer's name, and the product name. If the frontend calls three separate endpoints, the page must manage request order, combine data, and handle multiple failure states. The web app does this once, and the mobile app does it again. This course uses Node.js and Express to move that repeated work into a BFF, then gradually extracts business services that can run independently.
After this article, you will be able to explain where a BFF sits in the request flow, distinguish page data adaptation from business rules, and decide whether your project needs this extra layer.
You should already know Node.js, Express routing, HTTP status codes, and basic database operations. This course does not revisit those fundamentals; new architecture concepts are explained through the order example.
⚠️ What Happens When the Frontend Calls Multiple Endpoints?
Consider an order details page. The order endpoint returns the total, user ID, and product ID, but the page also needs the user and product names. The frontend must fetch the order first, use its two IDs to fetch the user and product, and then combine all three results.
Fetch order → Get userId and productId → Fetch user and product → Assemble page data
This gives the frontend several extra responsibilities:
- Sequence requests: User and product queries depend on IDs from the order, so they cannot start before it arrives.
- Handle partial failures: If the order loads but the product endpoint fails, the page must decide whether to show an error, retry, or hide some content.
- Adapt different APIs: The three endpoints may use different field names, nesting, and error formats, each requiring its own conversion.
- Maintain duplicate composition logic: Web and mobile clients may each implement the same queries and data composition when both need order information.
Multiple requests do not inherently indicate a design problem. Direct calls are reasonable when there are few endpoints and their responses already meet the page's needs. Centralizing this work becomes worthwhile when the same composition logic recurs across pages or clients.
🧱 What Is a BFF, and How Does It Differ from a Business Backend?
BFF stands for Backend for Frontend. It organizes APIs around the needs of a frontend. An order service answers “What is the order?”; a BFF answers “What does the order details page need to display?” Both can be written in Express. The difference is their responsibility, not their framework.
Is BFF Development Frontend or Backend Work?
A BFF runs on the server, but a backend engineer does not have to write it. Frontend engineers who know Node.js and Express can also build a BFF. Distinguish who owns the code from where the code runs.
| Comparison | Frontend page | BFF | Business backend |
|---|---|---|---|
| Runs in | Usually a browser or app | Server | Server |
| Main responsibility | Display content and handle user interactions | Call and adapt business APIs for pages | Enforce business rules and read/write business data |
| Typical developers | Frontend engineers | Frontend, backend, or full-stack engineers | Backend engineers |
For example, an order details page needs a user name and product name:
- When frontend engineers own the BFF: They can implement
/bff/orders/:idin Node.js, call the order, user, and product APIs, and return data shaped for the page. The frontend team can adjust fields without asking the business backend team for a dedicated endpoint each time. - When backend engineers own the BFF: They implement the same endpoint and aggregation logic, while the backend team maintains deployment, service calls, and error handling.
The technical responsibilities are essentially the same; team ownership and maintenance responsibilities differ. Whoever builds it, a BFF must run on the server even though it serves the frontend. It should not define core business rules such as order pricing or inventory deductions. Business services remain responsible for those rules.
🛠 How Does a BFF Serve Different Frontends?
Without a BFF, the browser fetches an order, then queries the user and product using its userId and productId. The browser must understand the fields and error formats of all three APIs. With a BFF, it only requests /bff/orders/o1, where o1 is the target order ID.
The BFF sits between the frontend and business services. It processes a request as follows:
- Query the order service for order
o1, obtaining its total, user ID, and product ID. - Query the user and product using those IDs. These queries are independent and can start concurrently.
- Select the fields the page needs, combine them into one response, and return it to the browser.
The BFF now handles the request orchestration and data composition previously performed by the browser. The browser receives:
{
"id": "o1",
"customerName": "Lin",
"productName": "Mechanical Keyboard",
"totalCents": 59800
}
totalCents stores an integer amount in fen, the hundredth of a yuan. The BFF does not recalculate the order price: the product's current price may differ from its price when ordered. It uses the amount saved by the order service, and the frontend formats it as 598.00 yuan.
Different frontends do not necessarily need identical responses. A mobile order card may need only the four fields above; a desktop details page may also need quantity and a user link. The BFF fetches data from the same business APIs and selects fields according to each page's contract, so each client does not have to reshape the full dataset itself.
A BFF's primary responsibility is to meet frontend needs; API aggregation is only one way to do that. Even when calling a single business API, it may need to rename fields or reshape data. Frontends with similar needs can share a BFF; those with substantially different needs can maintain separate BFFs. The decision depends on adaptation needs and maintenance costs, rather than requiring every frontend to use one response format.
One frontend request can still trigger three internal requests. A BFF reduces the calls the browser must orchestrate; it does not eliminate work between services or guarantee faster responses.
💡 When Is a BFF Useful?
| Project situation | Possible approach |
|---|---|
| One page, one business endpoint, and a suitable response | Call it directly and keep things simple |
| Multiple pages repeatedly combine the same backend data | Move page composition logic into a BFF |
| Desktop needs full details while mobile needs a summary | Have the BFF provide different response shapes |
| Complex pricing or inventory deduction rules | Keep them in business services; the BFF does not take over |
Deploying a separate BFF adds another service to run and maintain, and another point of failure. Small teams can start with separate page adaptation and business modules in one application, then extract independent processes when release schedules or load actually diverge.
❓ Questions and Answers
Q1: Does having a BFF mean the architecture uses microservices?
No. A BFF can call a monolithic backend or multiple services. Organizing APIs for pages is separate from splitting the business backend into services.
Q2: Does every frontend need its own BFF?
No. Consider separate BFFs only when differences in response structure, release schedules, or ownership justify the extra cost.
🧪 Exercise
Using this article's order page, decide whether each operation belongs in the frontend, BFF, or business service, and explain why:
- Call the user API to retrieve a name and include it in the order page response.
- Calculate the amount due when the order is placed using discount rules, and save it in the order.
- Format
totalCents: 59800from the response as598.00yuan on the page.
Suggested answers:
- Item 1 belongs in the BFF. It composes data for the page; the user service still provides the user information itself.
- Item 2 belongs in the business service. Discount rules determine the amount actually charged and must be enforced consistently by order pricing logic, rather than decided independently by each page's adaptation logic.
- Item 3 belongs in the frontend in this design. It changes presentation without changing the amount stored in the order.
You should be able to explain that the same amount is both a business calculation result and displayed content. Assign responsibility based on the operation performed on the data, rather than whether the field appears on a page.
🎉 You can now decide whether a project needs a BFF and understand the boundary between page adaptation and business services!
