AlgoMaster Logo

Backend-for-Frontend

Medium Priority8 min readUpdated November 12, 2026
Listen to this chapter
Unlock Audio

Modern applications often support multiple types of clients, such as web applications, mobile apps, tablets, and even smart TVs.

Although these clients may use the same backend services, they often have different requirements.

For example, consider an e-commerce platform that supports both a web application and a mobile application.

The web application might display detailed product information, customer reviews, recommendations, and related products on a single page.

The mobile application, however, might show only the product name, price, image, rating, and availability to keep the interface simple and minimize network usage.

If both clients use the same general-purpose backend APIs, they may need to make multiple requests or receive significantly more data than they actually need.

This is where the Backend-for-Frontend (BFF) pattern becomes useful.

A BFF is a backend layer designed specifically for the needs of a particular frontend application or group of clients.

It sits between the frontend and the underlying backend services, providing APIs optimized for that frontend's requirements.

1. What Is Backend-for-Frontend?

Backend-for-Frontend is an architectural pattern in which different frontend applications have dedicated backend layers.

Instead of forcing every client to interact directly with the same collection of backend services, each frontend communicates with a backend designed around its particular needs.

For example, an e-commerce platform might have:

  • Web BFF: Serves the desktop and web application.
  • Mobile BFF: Serves Android and iOS applications.
  • Partner BFF: Serves external business partners.

Each BFF communicates with the underlying backend services but exposes APIs tailored to its consumers.

Each frontend has a dedicated BFF while sharing underlying business services.

The important idea is that BFFs are organized around frontend needs, while backend services are organized around business capabilities.

For example, the Product Service remains responsible for product information, regardless of whether the request comes from the web or mobile application.

The BFF decides how that information should be collected, transformed, and presented to its frontend.

2. Why Do We Need a BFF?

A BFF primarily addresses two common problems: over-fetching data and excessive client-to-server requests.

Over-Fetching

Over-fetching happens when an API returns more data than the client needs.

Suppose a product API returns:

A desktop application might use most of this information.

However, a mobile product listing might need only the product ID, name, price, and rating.

Returning the full response wastes bandwidth and increases the amount of data the mobile application must process.

A Mobile BFF can return a smaller response:

This gives the client exactly what it needs without requiring the underlying Product Service to support every frontend-specific response format.

Excessive Network Requests

A frontend often needs information from multiple backend services to display a single screen.

For example, an order details page might require:

  1. Order details from the Order Service.
  2. Product information from the Product Service.
  3. Delivery status from the Shipping Service.
  4. Payment information from the Payment Service.

Without a BFF, the frontend may need to call four different APIs.

This creates additional network requests and requires the frontend to understand how different backend services work.

With a BFF, the frontend can make a single request:

The BFF fetches the required information from the backend services and combines it into one response.

This is particularly useful for mobile clients, where network latency and connection quality can significantly affect performance.

3. Core Responsibilities of a BFF

A BFF typically handles several frontend-specific concerns.

Data Transformation

Different clients may need the same underlying information in different formats.

For example, a web application might display detailed order information, while a mobile application displays a simplified summary.

Each BFF shapes the same underlying data for its own interface.

Client-Specific Business Presentation

Some logic is specific to how a frontend presents information.

For example, a mobile application might require a simplified checkout summary, while a desktop application displays a detailed breakdown.

The BFF can handle presentation-oriented decisions, such as selecting fields, organizing sections, and formatting response structures.

Authentication and Session Handling

A BFF can also simplify authentication for browser applications.

In one common pattern, the BFF manages OAuth tokens on the server and exposes a secure, HTTP-only session cookie to the browser.

This reduces the need to expose access tokens directly to frontend JavaScript.

However, the BFF must still implement appropriate protections, including CSRF defenses for cookie-authenticated state-changing requests.

Backend services should continue enforcing their own authorization requirements.

Response Caching

A BFF can cache data that is frequently requested by its frontend.

For example, a Mobile BFF might cache product categories or frequently accessed product summaries.

Caching can reduce latency and lower the load on backend services.

However, cache policies must account for data freshness and user-specific information. Sensitive personalized responses must not be shared across users.

4. How a BFF Processes a Request

Let's walk through an example involving an order details screen.

The mobile application makes the following request:

The Mobile BFF receives the request and performs these steps:

  1. Validates the user's session or authentication credentials.
  2. Requests order details from the Order Service.
  3. Retrieves relevant product information from the Product Service.
  4. Fetches shipment status from the Shipping Service.
  5. Combines the results into a mobile-friendly response.
  6. Returns the response to the application.
Calls can run in parallelGet order detailsOrder requestProduct requestShipping requestCombined responseMobile AppMobile BFFBackend Services
9 / 9
algomaster.io

The Mobile BFF aggregates information from multiple backend services.

The frontend now makes one request instead of coordinating multiple backend calls.

The simulation below uses a mobile home screen instead of the order details screen. On one side, the phone calls the user, orders, recommendations, and promotions services itself over the mobile network. On the other, it makes one call to a mobile BFF, which makes the four calls inside the datacenter and trims the response. Compare the totals: four round trips and 48 KB in 1.2 s against one round trip and 6 KB in 0.32 s.

5. BFF vs API Gateway

BFFs and API Gateways are related concepts, but they solve different problems.

An API Gateway primarily manages incoming API traffic and enforces common policies.

A BFF focuses on providing frontend-specific APIs and response structures.

Scroll
AspectAPI GatewayBFF
Primary purposeManage API trafficOptimize APIs for frontend needs
RoutingCore responsibilityUsually limited
AuthenticationCommon policy enforcementClient-specific session handling
Data aggregationUsually limitedCommon responsibility
Data transformationLightweightFrontend-specific
Business logicAvoidLimited to presentation-oriented logic
ConsumersMultiple client typesSpecific frontend or client group

These components can work together.

For example:

The API Gateway handles shared policies, while each BFF provides APIs optimized for its clients.

A BFF does not necessarily require a separate API Gateway. In smaller systems, the BFF itself may handle routing, authentication, and other entry-point responsibilities.

6. When Should You Use a BFF?

The BFF pattern is particularly useful when different frontend applications have significantly different data requirements.

Consider using a BFF when:

  • Web and mobile applications require different response structures.
  • Frontends frequently combine data from multiple backend services.
  • Network latency makes multiple client-side requests expensive.
  • Frontend teams need to evolve their APIs independently.
  • Backend services expose APIs that are too granular for frontend use cases.

However, a BFF is not always necessary.

If the application has only one frontend and a simple backend, introducing a dedicated BFF may add unnecessary complexity.

Similarly, if multiple clients have nearly identical requirements, they may be able to share the same API without dedicated backend layers.

The goal is not to create a BFF for every frontend automatically, but to introduce one when the benefits justify the additional service.

7. Challenges and Trade-offs

Although BFFs simplify frontend development, they introduce their own challenges.

Additional Infrastructure

Every BFF is another service that needs deployment, monitoring, scaling, and maintenance.

If an organization has many frontend applications, managing multiple BFFs can increase operational overhead.

Code Duplication

Different BFFs may implement similar aggregation or transformation logic.

Some duplication is acceptable because each BFF should be independently adaptable.

However, shared business rules should not be copied across BFFs. They belong in backend services or shared domain components.

Increased Backend Traffic

A single frontend request can trigger several downstream calls.

For example, one dashboard request might result in five backend requests.

At high traffic volumes, this can create significant load on shared services.

BFFs should use efficient batching, caching, and aggregation strategies where appropriate.

Failure Handling

A BFF often depends on multiple backend services.

If one service becomes slow, it can affect the entire response.

Use appropriate timeouts, parallel requests, and controlled fallback behavior.

Ownership and Team Boundaries

A BFF works best when the team responsible for the frontend can also influence or own its BFF.

This allows the API contract to evolve alongside the user interface.

Without clear ownership, a BFF can become another centralized backend service that slows down frontend development.

Key Takeaways

Backend-for-Frontend is an architectural pattern that creates frontend-specific backend layers.

It helps applications reduce unnecessary network requests, avoid over-fetching, and provide APIs that match the needs of different clients.

BFFs are especially valuable in microservices architectures where a single frontend screen may require information from several backend services.

However, they introduce additional infrastructure, potential code duplication, and new failure points.

A good BFF keeps frontend-specific concerns close to the frontend while preserving core business logic and data ownership in shared backend services.

Quiz

Backend-for-Frontend Quiz

10 quizzes