Why “Backend for Frontend” is the Right Approach for Modern Applications

Fikih Firmansyah
4 min readSep 24, 2024

--

Photo by Hisu lee on Unsplash

In the world of modern application development, we are often faced with the need to serve various frontend platforms-from web applications, mobile applications, to IoT applications. Each of these platforms has different characteristics and needs, both in terms of UI, data format, and performance. This is where the Backend for Frontend (BFF) pattern emerges as a solution. In this article, we will discuss what BFF is, why it is needed, and how it can be implemented effectively.

What is Backend for Frontend (BFF)?

Backend for Frontend (BFF) is an architecture where one or more backends are built specifically to fulfill the needs of one particular frontend. Each frontend-whether it’s a web, mobile, or other application-has its own backend that handles business logic, data processing, and information presentation tailored to the needs of that frontend.

Instead of using one monolithic backend to serve different types of frontends, BFF breaks down the backend based on the specific needs of each platform, so that each frontend only receives relevant data and features. This improves efficiency, performance, and overall user experience.

Why is BFF Important?

As technology evolves, the need for an optimized user experience grows. The Backend for Frontend pattern emerged to address some of the common challenges faced when using one backend for all types of frontends. Here are some of the reasons why BFF is so important:

Different Frontends, Different Needs

Web and mobile applications often require different data in terms of volume and format. For example, a mobile app may require faster and more concise responses than a web app which may require more complete data. BFF allows the backend to adapt to these specific needs.

Performance and Bandwidth Optimization

Mobile applications often operate on slower networks and may require bandwidth savings. With BFF, you can simplify the data sent to mobile without affecting other frontends such as web applications that require more data.

Reduced Load on Frontend

In scenarios without BFF, frontends often have to manipulate and manage raw data from monolithic backends. This increases the complexity on the frontend. With BFF, the backend can perform all the necessary transformations and business logic before sending the ready-to-use data to the frontend, thus reducing the burden on the frontend.

Easier Maintenance

By separating the backend for each frontend, the development team can easily maintain different backends according to the needs of the frontend. For example, changes to the web app backend will not affect the mobile app backend. This also allows for faster and more secure updates and fixes.

Case Study: Web vs Mobile Application

To better understand how BFF works, let’s look at a simple case study:

Imagine that you are developing an e-commerce application that has two main frontends: a web app and a mobile app. If you use one backend for both, the mobile app might receive unnecessary data or have to do a lot of work to reformat the received data. For example, a mobile app user may only need minimal product details (name, price, and a small image), while a web user may need more detailed information (full specifications, user reviews, and product recommendations).

With the BFF pattern, you can create two separate backends:

  • Backend for web applications: Presents complete product data, including user reviews, product recommendations, and more complex filters.
  • Backend for mobile apps: Provides more concise product data, formatted for fast performance, with only basic information such as name, price, and thumbnail images.

With this approach, the mobile frontend is not overloaded with unnecessary data, while the web frontend can get all the information it needs for a richer user experience.

How to Implement Backend for Frontend

Here are some steps and best practices to follow when implementing the BFF pattern:

Identify Frontend Needs

The first step in implementing BFF is to understand the specific needs of each frontend. What are the data requirements? How fast should the response be provided? Are there operations or business logic that must be executed on the backend? This identification is important to build an efficient and suitable backend.

Separate Backend Based on Platform

After understanding the frontend requirements, you can start building separate backends for each platform. There may be a backend for web applications, another backend for mobile applications, and perhaps another backend for IoT applications if required. These backends can share some components, but they should be optimized for each of the frontends.

Integrate with API Gateway

The BFF pattern often works well when combined with an API Gateway. API Gateways act as a link between various frontends and backends. It can handle things like authentication, request management, or rate limiting, so that specific backends can focus on processing business logic and data transformation.

Pay Attention to Scalability and Security

As the number of frontends to support grows, you may need to think about how to ensure that each backend is scalable. In addition, each backend should be configured with proper security controls to protect user data and maintain consistency across the platform.

Pros and Cons of BFF

Pros:

  • Flexibility: Each frontend gets a backend that suits its needs.
    Performance Optimization: Backends can optimize data and logic according to the platform.
  • Focused Scalability: Allows for more modular backend management and development.

Disadvantages:

  • Infrastructure Complexity: Requires multiple backends to be managed, which can increase development and operational complexity.
  • Logic Duplication: Some business logic may need to be duplicated across different backends.

Conclusion

Backend for Frontend (BFF) is an ideal pattern for modern application architecture, especially when you have to support multiple frontend platforms that have different needs. By building a specific backend for each frontend, you can improve efficiency, performance, and overall user experience. While this approach requires more complex management, the benefits in terms of optimization and scalability make it the right choice in many cases.

If you are developing an application with multiple frontends, consider the BFF pattern as a solution to provide a better and more efficient user experience.

--

--

Fikih Firmansyah
Fikih Firmansyah

Written by Fikih Firmansyah

Back End Developer at Universitas Sumatera Utara || Google Developer Groups Medan

No responses yet