Author: Idle fish technology – ancient style

The client of Flutter+Serverless does not just write two-end code, but expands the working boundary of the client to form a complete business closed loop. During the implementation and practice of the new R&D mode, I have been thinking about how to improve the R&D experience and quality of FaaS. The following are the problems encountered in the implementation process.

  • How to improve FaaS r&d experience? FaaS layer usually directly adds business codes one by one in the trunk. In this way, the dependence between domain data is not clear, and a lot of work needs to be added when the domain data needs to be replaced, adjusted in sequence or changed from serial to parallel in subsequent maintenance.

  • How to improve the quality of FaaS r&d? When students on the client side write FaaS code, they need to add protective code and degradation strategy for all kinds of exceptions on the server side, which is easy to be omitted and lead to the overall quality decline.

What is ** task choreography? **
Review a complete business loop, including the mid-stage, domain, business, and rendering layers. In the cloud integrated scenario, FaaS side focuses more on the business layer and rendering layer for data aggregation, clipping, field mapping and structural adjustment.

For the following single service, the FaaS layer is assembled by six HSF (RPC framework) calls to retrieve data. Commodity information, receiving address and free fish currency can be executed in parallel, while red envelope, freight and inspection guarantee can be executed in parallel. Because of dependence on commodity information and receiving address, the two groups of tasks need to be executed in serial.
! [](data:image/gif; base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==)! [](https://img.alicdn.com/tfs/TB1wauNe_M11u4jSZPxXXahcXXa-518-470.jpg)
In the figure above, each node (for example, obtaining product information) can be abstracted into a task. Implementing this process through code is task choreography.
How does task scheduling improve the development experience **
The FaaS layer usually adds business code block by block directly to the trunk, which may be hundreds or even thousands of lines in complex scenarios. The following is the single-page functional code written through the task choreography framework
! [](data:image/gif; base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==)! [](https://img.alicdn.com/tfs/TB1TEooPEY1gK0jSZFCXXcwqXXa-960-360.jpg)
  1. These parameters can be used by multiple tasks using map-type data as input parameters.

  2. Two apis, THEN and thenAll, are used for task scheduling. The THEN function indicates that the incoming function is executed sequentially, while the thenAll function needs to be executed in parallel.

  3. Call Apply for task link execution.

  4. Through chain calls, the overall structure is very clear and the framework is less intrusive.

You can see the above code entries, tasks choreographed, and results obtained in a very clear structure. From the code, you can see the number of tasks, the flow of tasks, the serialization and parallelism of tasks. Greatly improve the development experience through simplicity, less intrusion, and chain calls.
`! [](data:image/gif; base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==)! [](https://img.alicdn.com/tfs/TB1qIAzPBr0gK0jSZFnXXbRRXXa-1186-422.jpg)`
The ‘requestItemDO’ function is a common process for obtaining domain data. Firstly, it obtains userId and itemId parameters, obtains commodity information through HSF, and determines whether the request is valid after getting the result. If it is valid, specific Model data will be returned.
** Application scenarios for task orchestration **
** Task type **
Task choreography is not limited to HSF tasks. Since the framework only requires a function to be passed in, it can support any type of task choreography, such as HSF, MetaQ, Tair, DB, etc.
! [](data:image/gif; base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==)! [](https://img.alicdn.com/tfs/TB136QAcIVl614jSZKPXXaGjpXa-846-260.jpg)
** Task choreography **
An example of a single page is a serial-parallel scenario, and the task choreography framework supports any number of serial-parallel, complex scene task choreography. Development students only need to develop the task function, and then according to the task needs serial or parallel, call specific API interface, do not care about the various operation details of synchronous and asynchronous.
! [](https://img.alicdn.com/tfs/TB1rO4NOUY1gK0jSZFCXXcwqXXa-830-516.jpg)
** Asynchronous task **
FaaS side code is usually IO intensive tasks such as PRC calls, database reads and writes, etc. Dart supports asynchrony based on an Event Queue. The advantage of Dart is that it can wait for multiple I/O events at the same time without blocking the main thread, thus reducing the overall RT(Response-time) Response time. The Dart asynchronous mechanism takes the following figure:
! [](https://img.alicdn.com/tfs/TB18moXfk9l0K4jSZFKXXXFjpXa-536-608.jpg)
** Task reuse and precipitation imagination **
! [](data:image/gif; base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==)! [](https://img.alicdn.com/tfs/TB1XfMPdggP7K4jSZFqXXamhVXa-796-328.jpg)
For FaaaS side, the acquisition and processing of single data is abstracted into tasks. As more and more tasks are deposited, the business solution layer will emerge through the assembly of multiple tasks. Security verification is required in many scenarios, such as: These common rules can also be reused in other scenarios, such as security verification rules in group chat. Three-terminal integration scenario development architecture, from the data acquisition, the assembly to the front-end UI can be finished in a developer, the link can be integrated components such as right to precipitate, a component contains field data, converted to a ViewModel, client view components, thus forming the cloud of component reuse, promote the overall development efficiency.
** How does task scheduling improve r&d quality **
The client writes the FaaS layer code, You need to learn server QPS(Query Per Second), Reaction Time (RT), TPS (Transactions Per Second), traffic limiting protection, degrade protection, and hotspot protection. The biggest concern is how to ensure the stability of the FaaS layer code deployed on the Serverless platform and how to improve the quality without problems and failures. The quality problem can be analyzed from three aspects: anomaly classification, how to capture and anomaly handling.
** Exception classification **

First, summarize the common types of server exceptions:
  • Code exceptions: null pointer exceptions, out-of-bounds array exceptions, etc

  • System exception: machine exception, memory overflow, thread pool full, DB exception, etc

  • Interface exception: The interface response times out or the downstream dependency is abnormal

! [](data:image/gif; base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==)
** Exception catch **
No matter what kind of exceptions occur at the FaaS layer, users should not be unable to use functions for a long time due to exceptions. You need to consider exception capture and design an overall degradation, monitoring, and alarm scheme. Usually, server-side development is to add try catch in the scenario of possible problems, which is not simple enough to write the code. Developers expect to see only business function code like the function ‘queryItemDO’ above. As for capture, general monitoring and alarm, task choreography framework will carry out unified bottom processing.
! [](data:image/gif; base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==)! [](https://img.alicdn.com/tfs/TB14Q2bdIVl614jSZKPXXaGjpXa-700-270.jpg)
The task choreography framework transmits the captured exception information to the developer students in two ways: onError for a single task and catchError for the whole link. In these two ways, the exception stack can be acquired gracefully and handled flexibly.
! [](data:image/gif; base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==)! [](https://img.alicdn.com/tfs/TB1SHKNgk9l0K4jSZFKXXXFjpXa-760-68.jpg)
This section describes how to set the timeout period for the calling link to prevent the timeout of the entire interface caused by the waiting timeout of the task.
** Exception & Monitor **
! [](https://img.alicdn.com/tfs/TB1hXBNOUH1gK0jSZSyXXXtlpXa-1812-576.jpg)
Sunfire is a server-side monitoring platform with a complete set of real-time analysis and monitoring system for massive data, providing monitoring capabilities from various perspectives, such as system, application and business. If the configured rules are triggered, an early warning will be sent. The task orchestration framework outputs the captured exceptions and the current FaaS name and other information in a unified log, and configates common rules on the Sunfire platform to monitor exceptions.
** Earnings and outlook **
Jade, the task scheduling framework, can solve the two problems proposed in this paper:
  • Improve research and development experience: developers arrange tasks in the form of chain call, supporting any type of tasks, all tasks can be flexibly combined, and the execution sequence of tasks can be arbitrarily adjusted.

  • Improve the quality of r&d: The task orchestration framework adds mechanisms for exception type sorting, exception capture and exception monitoring.

Expectations of task scheduling framework and flexible arrangements for any type of task, not only the follow-up during the development phase through the source output technical documentation and flow chart, for single task and task link test, through the task scheduling framework as gripper through effective demand, development, testing, and operational stage, so as to improve the development efficiency improved security goals.