BFF function based computing architecture

5C2E790C-1486-49bf-86FA-418BF79C9682.png

What's BFF

BFF stands for Backends For Frontends (service in front of the back-end), originated in 2015 Sam Newman blog post "Pattern: Backends the For frontends - Single-Purpose Edge Services for UIs and External parties" .

Separate front and rear ends and a micro-services popular, the boundary at the rear end there is usually a service API layer, a plurality of micro-services to a reduction in the system, after a series of the polymerization process, and cutting the like adapted, to provide up to the front end API HTTP protocol.


Then with the rise of the mobile side, there have been many-fold concurrent development scenario H5, iOS and Android, because the screen size of the mobile terminal is relatively small, so the information side display of traditional Web and have a greater difference, and mobile access to connection end number and the amount of data have higher requirements. At this time, the development of common API layer will encounter a number of difficulties, such as the need to provide different API for different end. The design and presentation logic on different ends of the API correlation is strong, it is not suitable to be responsible for the team or the backend API team. Because these API's maintenance personnel will be sandwiched between the front and rear ends to do coordination and choice, very tired heart.

Sam Newman has two companies in the REA and SoundCloud practice to do independent Backend API for different ends, called BFF. To address the different needs of different end of the API.

BFF benefits

Legacy business support

Interface Specification some older systems may be relatively old, such is not the Restful. BFF layer by means of interface converters do something better fit the needs of end technology development.

Coordination and stability in the Taiwan changing needs of end

End the fast changes mainly reflected in two aspects:

  • Technological innovation: technology updates on the end of faster, js framework level is not poor. Mobile end, there are many choices, H5, Java / OC, Kotlin / Swift, React Native, Flutter, and so on.
  • Business change: change in front-end products tend to business changes more frequently than the back end.

Differentiation capacity filled end side serving

Some products delivered to different countries, languages, the crowd, you can do some conversion BFF layer, such as the back end and user error can do some language-related translation here.

Lateral polymerization and polymerized based optimization

Some products involve a plurality of modules in service stations, as BFF Edge service layer functions as the polymerization API.

Business Effectiveness Evaluation on the end

Try a new experience in the end is inevitable to change the API. Without BFF, to A / B testing need to modify the front end and the API. If the mobile and Web team needs to run A / B testing how to do? A team may have to wait another team.

BFF so that different teams can be independently tested. You may find, first implemented in the experimental BFF in API changes, and then transplanted into the test A / B testing, and then transplanted into the core API, more convenient.

Some of the issues BFF

High resource costs

No matter how easy BFF, you need to provide a server running a little tight, then also need to provide several sets of deployment environment. Some large companies such as internal
requirements, no matter how simple applications require four servers, and the approval process server may be slower long.

Concurrency is difficult to guarantee

BFF layer generally consists of front-end development of the students, however BFF ensure high availability, students on the front end is often a challenge. When the sudden increase in traffic, which may occur BFF first layer off the hook, causing the entire system infrastructure availability is low.

Operation and maintenance difficulties

Who develops operation and maintenance, then the front of classmates may lack the operation and maintenance of online application experience, BFF operation and maintenance is also a big problem.

Serverless For Backend

Since Serverless especially the function calculation , after application deployment, if there is no traffic will not consume computing resources, but does not produce costs. When traffic increases, the platform will be hundreds of milliseconds speed expansion, traffic drop after computing resources behind (function instance) will also shrink to applications. But also it provides the user with a box and a monitor alarm log retrieval function.

Function calculates the resilient and elastic, pay-per-free amount and the operation and maintenance of the advantages of the traditional shortcomings corresponds exactly BFF's. So BFF will be deployed to function computing platform can perfect solve the above-BFF's.

When the deployment cost, but also for smaller BFF offers the possibility of dismantling. At this end can be organized in accordance with the corresponding service module BFF module. For example, front-end development platform operators responsible for their own BFF corresponding module development, front-end equipment center responsible for your own BFF, may be less conflict with each other, truly who enjoy who is responsible .

Calculated based on a function of the program

BFF function computing platform architecture embodiment has four layers: the end side, the gateway layer, layer BFF and service stations.

End side can maintain their familiar technology development programs. React example web client may select or Vue.js, the mobile terminal may select Java / Kotlin or Objective C / Swift. You can also select React Native or Flutter multiport solutions across this.

Layer gateway has two choices: API Gateway and HTTP Trigger. API Gateway's feature-rich, support the current limit, but will incur additional charges. HTTP Trigger support simple routing maps, binding domain, although it does not support limiting free for lightweight applications.

BFF layer service module in accordance with the recommended resolution, different functional modules to build a different function, if the differences between the interface modules of a larger end can be broken down into different functions. Fun tool then these functions are organized into several projects. Dismantling project may consider splitting accordance with the maintenance team, a different team to maintain different projects, and to reduce conflict between cross.

SFF development process

Let the local development, publishing process and service monitoring three aspects of the development process to see how to get SFF.

Local R & D

Local project is divided into three parts

  • APP / H5 - React Native end technology or the like Vue.js
  • SFF - FC function, a common express or egg
  • In Taiwan API interface - you can choose, or direct API Mock test environment.

Local debugging. Developers prefer the command line can use funcraft tool by local fun local start to start the service. Preferences desktop GUI developers can use the function calculation provided VSCode Plugin .

Unit testing can select their favorite testing framework: Mocha or Jest

The following is a proposed project structure

sffdemo
├── README.md
├── function
│   ├── package.json
│   ├── template.yml
│   └── user.js
├── package.json
└── src
    ├── component
    ├── layout
    ├── model
    ├── page
    └── service

src directory placed APP or the code of H5. function directory placement bff code, you can use a template template.yml ROS describing function, using fun tools for publishing.

Publishing Process

Daily develop recommendations issued using the command line, after installing and configuring fun tool, place the ROS description file in a template.yml BFF project, and then by means of fun deploy command for rapid deployment.

Novice can also choose to function Computing console , use ZIP file upload package release.

For more complex scenarios can be configured CI / CD. For example, code repository selection Gitlab / Github, build system select Travis CI / Gitlab CI / Jenkins, submit code to the code repository automatically trigger the build and release. More details can refer Serverless combat - Funcraft + OSS + ROS were CI / CD

Service Monitoring

About observability aspect, it provides a monitoring function is calculated out of the box, logs and alarms.

Cost advantage

Typically includes a user application load various types, different resource specifications and elasticity requirements. Function computing offers prepaid and postpaid metering mode to help you gain significant cost advantages in different scenarios. Prepaid refers to first determine the resource needs of the user application, a pre-specified number of resources to purchase coupons before use. Prepaid advantage is the low price, cheaper than the post-paid 70%; drawback is the application of dynamic load changes, in accordance with the peak buying resources will lead to lower resource utilization. Refers to post-paid user fees based on-demand application resources actually used. Is an example of the time calculating function execution request paid by the amount of resources, accurate to hundreds of milliseconds. If there is no request, no charge. It follows that the utilization of resources by the amount of 100%. The advantage of post-paid resource utilization is high, the disadvantage is the high price. Automatic retractable function allows you to calculate the pre-paid and post-paid resources seamlessly combined to have access to cost-competitive under different scenarios.

More specifically, costing and cost optimization scheme may refer to the function optimization calculation cost Best Practices

summary

Everyone on Serverless definition and floor may have a different understanding. By means of a function computing brings Serverless advantage, BFF who really do enjoy who is responsible, free and low cost of operation and maintenance.

" Alibaba Cloud native concern micro service, Serverless, container, Service Mesh and other technical fields, focusing cloud native popular technology trends, cloud native large-scale landing practice, most do understand the developer's native cloud technology circles."

Guess you like

Origin www.cnblogs.com/alisystemsoftware/p/12620972.html