BFF's First Exploration

The BFF Study Pathway

The topic of knowledge sharing by the department is: What is BFF and how to use it?

When I saw this topic, I was very confused, because I haven't touched it in my previous work, so this is an unknown field for me. If there is no way, then explore by yourself, and you can also expand your knowledge.

First of all, when encountering a new knowledge, I must first consult an experienced teacher, so I have a try mentality to see if there is a detailed explanation of BFF on station B. It is indeed an unpopular knowledge, no. That can only be understood through some blogs, so I checked some blogs, such as: CSDN, Zhihu, Nuggets, etc. In fact, the learning scope of blogs is also limited. Generally, there are only a few original understandings, and the others are reproduced. ;

After reading more than a dozen articles, in fact, I can only know what it is for, why it is like this, and how it is realized internally. It really needs to be explored in depth. In fact, BFF is not difficult to understand. It's just related to many knowledge points that I haven't heard before, such as: gateway, microservice architecture, GraphQL technology, etc.,


BFF generated background

Question one:

I believe that everyone will encounter this situation in their work, and then started the following dialogue:

Xiao Li: "Isn't it enough for the front end to request two interfaces and then assemble it?" – The back end pursues service sinking and decoupling

Xiaohong: "One less http request, is it so difficult to add another interface?" – The front end pursues a better user experience

Question 2:
Under normal circumstances, regardless of any performance issues, an interface on the back end can be used by different terminals, but the PC end is mainly for operations, involving adding, deleting, modifying and checking, and needs to return a lot of data, and everyone knows that Mobile phone terminals are generally used to display information, and the screen is limited, and four or five fields may be needed. The other obtained data has no effect, and it will also occupy the network speed and increase the delay


What are BFFs?

At this time we need to use BFF;

What we are going to talk about is the BFF layer, that is, Backend For Frontend (the backend that serves the frontend); it is not a technology, and it is usually called an adaptation layer or an aggregation layer;

So why is it called the adaptation layer and the aggregation layer?

The role of BFF is the user experience adaptation layer and API aggregation layer : mainly responsible for quickly following up UI iterations, combining and processing back-end interface services, and performing data: cutting, formatting, aggregation, etc.

It is equivalent to a peacemaker between the front and back ends . After adding a BFF layer between the background service and the front end, all the data aggregation tasks that need to request multiple microservices are done here. It is also a microservice itself, so it can provide an interface externally, so that the app can There is no need to request multiple times.
insert image description here
The following picture is a formed microservice architecture model. You can see that the BFF layer is very similar to the API gateway, and there can also be multiple services for different terminals;

insert image description here


Application scenarios of the BFF layer

1. Multi-terminal applications and aggregation services
At present, we have many terminal devices, such as Android, iOS mobile terminals and PC terminals. At the same time, we need an interface for back-end services. The terminals are different, and the back-end interfaces are also different;

If you write a public interface to return all the data, the screen of the mobile phone is narrow and you only need to display a few fields, all of which will consume memory and increase the delay; the PC side generally needs to obtain more data, It's okay; so in order to adapt to multi-terminal applications and facilitate future maintenance, we need BFF as middleware. On this middleware we will do some business logic processing;

2. Application cache

There are often some temporary data that need to be cached in the project, and the BFF layer, as the convergence point of the business, is closest to the user request, so the cache operation can be placed on this layer;

3. Third-party interaction
When it is necessary to interact with a third party in the business, put the interaction on the BFF layer, so that only the necessary information can be exposed to the third party, so as to facilitate the control of third-party access;


Advantages of BFFs

  • Can reduce communication costs: Back-end students pursue decoupling, and hope that client applications and internal microservices will not be coupled. By introducing the middle layer of BFF, the two sides can change independently
  • Multi-terminal application adaptation: displaying different (or smaller) data, such as the API for PC-side page design needs to support the mobile side, and found that the existing interface is strongly related to the desktop UI display requirements from design to implementation, and cannot easily adapt to the mobile side The display requirements are like a news recommendation interface on the PC side. The interface field is required on the PC side, but H5 does not need it on the mobile side. At this time, adjustments can be made at the BFF layer according to different terminals, and different (or less) API calls (aggregation) to reduce http requests

Disadvantages of BFFs

  • Repeated development: developing a BFF application for each device will also face some repeated development problems and increase development costs
  • Maintenance issues: Various BFF applications need to be maintained. In the past, the front end did not need to care about concurrency, but now the pressure of concurrency is concentrated on BFF
  • Complex link: The process becomes cumbersome. After the introduction of BFF, the R&D process of the front-end and server must be carried out at the same time. Multi-terminal releases and interdependence lead to cumbersome processes
  • Waste of resources: There are too many BFF layers, resource occupation becomes a problem, and resources will be wasted

"Happiness troubles" under the BFF layer:
insert image description here

Guess you like

Origin blog.csdn.net/qq_44182284/article/details/123841416