BFF

1. What is BFF 2. What problem does BFF solve 3Copy the code

What is a BFF

BFF is also called user experience adapter. Backend For Frontend is used to design apis For servers and processes service logic directly on servers. BFF is a logical layering, not a technology, and while BFF is a new term, the idea has a long history.

What problem does BFF solve

Backend A, BACKEND B, and Backend C…… The request is sent, and the return value of the different services is used to render different components of the page, i.e. a scene with many requests on one page.

At this point, you need to send three requests each time you visit the page. At the same time, in order to meet the different requirements of Android, iOS and Web, different API interfaces need to be written for different platforms. Whenever the value changes, Android, iOS and Web need to make modifications. At the same time, when we need to process a string, such as 140 characters, we need to implement it on each client (Android, iOS, Web), which is obviously quite expensive.

Therefore, we need BFF as middleware. On this middleware we will do some business logic processing:

When we have the BFF layer, we don’t need to worry about the migration of the back end of the system. Backend changes can be modified in the BFF layer in response.

For example, we added the BFF layer so that instead of sending 3 request pages per visit, we had one request.

How to use BFF

Many applications

We will consider the requirements of different devices when designing THE API, that is, to provide different apis for different devices. Although they may realize the same function, they have their own characteristics in accessing the API of the server due to the particularity of different devices, which need to be treated differently.

Service aggregation

With the rise of microservices, business processes that used to run in the same process are split into different services. This increases business flexibility while making front-end calls more complex. The emergence of BFF provides a convergence point for business service invocation for front-end applications. It shields the complex service invocation chain and allows the front-end to focus on the data it needs rather than the underlying services that provide the data.

Don’t add anything if it’s not necessary

While we are looking at the benefits of BFF, we should also be aware of the problems with code duplication and increased workload. If the BFF function is similar to that of an existing BFF, and the requirements for presenting data are similar, you should be cautious about adding a new BFF. Accordingly, the proposal is not necessary, mo add.

Access control

For example, the permission control in services is centralized in the BFF layer to make the lower level services more pure and independent.

The application cache

Often there is some temporary data that needs to be cached in a project, and the BFF is placed in the BFF layer as the business convergence point closest to the user request.

Third party entrance

When a business needs to interact with a third party, the interaction is placed in the BFF layer so that only the necessary information is exposed to the third party and its access can be easily controlled.