07 Function Integration With Cloud Services for End to End Solutions

07 Function Integration with Cloud Services for End-to-End Solutions #

Summary: Alibaba Cloud Serverless product, Function Compute, can act as glue to connect other cloud services and provide end-to-end solutions, simplifying the programming model and quickly achieving top-level business goals.

Decomposing Traditional Monolithic Applications #

img

First, let’s look at two common programming models in monolithic applications, as shown in the above diagram. One is the UI-driven model, and the other is the Message-driven model. In this architecture, the client side may not be very intelligent, and many logics (such as authentication, page navigation, search, transactions, etc.) are implemented by the server-side application. As the complexity of business logic increases, the server-side application becomes more bloated and difficult to maintain.

In the Message-driven asynchronous message processing model, the user needs to implement a persistent, highly available consumer service. To focus more on specific business logic development and efficiently utilize cloud service architecture, decomposing a large monolithic application using serverless architecture is a very good solution. The key is how to select and use the correct cloud services for each component of the application, and using functions as glue to connect managed services in the cloud is a good practice.

img

As shown in the above diagram, after switching from UI-driven to Serverless architecture:

  • Third-party BaaS services replace authentication logic;
  • Clients can directly access data sub-services (BaaS) on the architecture and third-party platforms through temporary tokens;
  • The server-side logic of the pet store can be moved to the client side, such as tracking user access, reading databases, and transforming them into visual views. The client side gradually transitions into a single-page application;
  • For CPU-intensive or data-intensive operations, such as searching, using FaaS eliminates the need for a continuously running server;
  • The purchase function is implemented using another FaaS and placed on the server for security reasons.

After switching from Message-driven to Serverless architecture:

Compared with the monolithic application example, the modifications here are minimal. FaaS functions are used to replace long-standing message consumer applications, and the high availability of message consumption is handled by the cloud platform.

Event-Driven Architecture and Orchestration Empower Complete Serverless Applications #

img

Currently, many people generally equate FaaS, which stands for Function as a Service, with Serverless. For example, Alibaba Cloud’s Function Compute and AWS Lambda. However, in reality, there are many other cloud services that are Serverless. They, together with Function Compute, form a complete Serverless application, allowing users to focus entirely on their top-level core business. For example, users can directly use the API Gateway to free themselves from the cumbersome work of API-related tasks such as rate limiting and authentication. They can directly use Serverless NoSQL databases like TableStore or object storage like OSS to persist data, replacing the need to manage their own database instances. They can use SLS or Datahub to collect data from external systems, and use message services like MNS/MQ to manage messages, etc.

Users can use individual functions to connect these Serverless services, achieving the goal of building complex business logic and applications. Here, users can also choose Serverless workflows to orchestrate functions and other cloud services, simplifying the development and operation of business processes (such as writing code for task coordination, state management, error handling, retries, etc.), allowing users to focus on business logic development. Of course, users can also use the development toolchain provided by Alibaba Cloud to simplify automated deployment and continuous integration. These out-of-the-box tools can help users quickly achieve their desired goals and effects.

For a large and complex monolithic application or a service-oriented architecture, developers have to take care of everything, including writing code, managing and deploying databases, and other related backend services. Switching to Serverless architecture, you can see that specific modules are handled by specific managed cloud services, and then use functions that implement specific business logic to connect them, achieving decoupling. In order to make this architecture work more efficiently, event-driven is an essential feature. For example, when a user attempts to upload a file to OSS or update a entry in TableStore, some logic processing is automatically done. For developers, the most important thing is to know what events can trigger the execution of their logic.

Serverless Gluing of Cloud Services Example #

Here is an interesting example:

img

As shown in the above diagram, when a user uploads an image file, a message event triggers an FC function to generate and store a thumbnail of the image in OSS. Then, another FC function is triggered to write the update information of the image to the TableStore database. Finally, another FC function is triggered to update the search module. Throughout the entire process, file processing and storage, search services, and TableStore database services are glued together by several FC functions into a single business processing logic.

Reference: https://martinfowler.com/articles/serverless.html