@wscld
Published on

Why BFF?

Authors
  • avatar
    Name
    Wesley Caldas
    Twitter

Why BFF?

In the evolving world of software architecture, providing the best user experience often means tailoring your backend to the unique needs of each frontend. This is where Backend for Frontend (BFF) comes into play.

What is Backend for Frontend (BFF)?

Backend for Frontend is a design pattern where a dedicated backend service is created for a specific frontend application. Instead of having one generic backend serve all types of clients (web, mobile, desktop), each frontend has its own backend that acts as a mediator between the UI and core backend services.

Why Use a BFF?

Different frontend applications often require different data shapes, levels of detail, and behavior. A BFF provides:

  • Custom APIs per platform: Tailored responses for mobile, web, or other clients.
  • Simplified frontend code: The frontend doesn't need to handle complex data transformations.
  • Improved performance: Reduces over-fetching and under-fetching of data.
  • Cleaner architecture: Separation of concerns between presentation and business logic.

Real-World Example: E-commerce Platform

Imagine you're building an e-commerce platform with a web app and a mobile app.

  • The web app displays rich product details, reviews, related items, and dynamic filtering.
  • The mobile app needs only basic product info and quick navigation due to limited screen space and bandwidth.

Using a BFF pattern:

  • The Web BFF can fetch detailed product data, user-specific recommendations, and extended review content from various backend services and format it for the web.
  • The Mobile BFF fetches only essential product fields (e.g. name, price, thumbnail) and compresses the response for better performance.

Each BFF handles the exact needs of its frontend, improving both performance and developer experience.

How It Works

Here’s a simplified flow:

  1. A user interacts with a frontend (e.g., mobile app).
  2. The frontend sends requests to its corresponding BFF.
  3. The BFF aggregates and transforms data from backend services.
  4. The BFF sends a response tailored for that frontend.

When Not to Use a BFF

While BFFs are powerful, they're not always necessary. Avoid using a BFF when:

  • Your application is small with few frontend clients.
  • The frontends can efficiently consume a shared API.
  • Adding a BFF would increase unnecessary complexity.

Should Frontend Developers Build the BFF?

In many teams, yes, frontend developers are the best people to build and maintain the BFF.

Why?

  • Deep understanding of UI needs: They know exactly how the data will be used.
  • Speed of iteration: No need to wait for backend teams to make small adjustments.
  • Shared language and stack: Many BFFs are written in JavaScript or TypeScript (e.g., using Node.js), which frontend developers are already comfortable with.

But watch out for:

  • Scope creep: BFFs should avoid taking on heavy business logic.
  • Security concerns: Ensure proper validation, error handling, and authentication.
  • Coordination with backend teams: Especially for API contracts and data consistency.

A well-structured team can treat the BFF as an extension of the frontend, owned and maintained by the same developers, leading to a faster, more agile delivery process.


The Backend for Frontend pattern is a powerful way to optimize the communication between frontends and backend services. It enhances developer productivity, user experience, and system scalability, especially in multi-platform environments.

If you're building apps for multiple platforms, consider implementing BFFs to keep your architecture clean and your frontends efficient.