The author | : west flow function of cloud computing experts (ali)

Spring Boot is a suite based on the Java Spring framework that comes preloaded with Spring components and allows developers to create standalone applications with minimal configuration.

In cloud native systems, there are a large number of platforms that can run Spring Boot applications, such as virtual machines and containers. One of the most attractive, however, is to run Spring Boot applications Serverless. I will analyze the advantages and disadvantages of SpringBoot application running on Serverless platform from five chapters, including architecture, deployment, monitoring, performance and security, through the series of articles “SpringBoot Serverless Actual Combat”.

To make the analysis more representative, I chose Mall, an e-commerce app with more than 50K stars on Github, as an example. This is the first article in a series that looks at Serverless Spring Boot applications from an architectural perspective.

Introduction to Mall Architecture

Mall is a set of e-commerce system, including the front Mall system and background management system, based on Spring Boot + MyBatis. The front desk mall system includes home page portal, product recommendation, product search, product display, shopping cart, order process, member center, customer service, help center and other modules. Background management system includes commodity management, order management, membership management, promotion management, operation management, content management, statistical reports, financial management, authority management, setting and other modules.

The structure of Mall is shown in the following figure, including gateway layer, application layer, and data storage layer. The request first goes through the gateway to the Spring Boot application service. The gateway implements load balancing and traffic control. The application layer contains three Spring Boot applications and one front-end application:

  • Mall-admin: background mall management system
  • Mall-portal: indicates the front mall system
  • Mall-search: A search system for Elasticsearch
  • Mall-admin-web: front end display of mall-admin, based on Vue+Element implementation

Mall uses MySQL, Redis, MongoDB, ElaisticSearch and other databases. Primary service data is stored in MySQL, cache data is stored in Redis, user behavior analysis data is stored in MongoDB, and search data is stored in ElasticSearch. Spring Boot application services use RabbitMQ for asynchronous communication.

Serverless Computing Platform – An introduction to function computing

Function Compute is currently the only Faas product selected by Forrester as a Leader phenomenon in China. It is an event-driven, fully managed Serverless computing service. Developers do not need to manage servers and other infrastructure. After users upload code packages or container images, functional computing automatically prepares computing resources and runs the code in a flexible and reliable manner.

The product advantages of function calculation are summarized as follows:

  • Efficient o&M: Focuses on business logic development and does not need to worry about o&M operations such as server purchase and automatic scaling

  • Elastic high availability: The system does not automatically recycle the reserved instances, but can stay in the system for a long time without destroying them, eliminating the delay burr caused by cold startup

  • Low cost on demand: The pay-as-you-go model charges resources according to actual usage and has high resource utilization

  • Stable and reliable: Function computing is deployed in a distributed cluster and supports multiple availability zones

Function computing provides comprehensive observation and problem diagnosis capabilities, but its most prominent feature is the built-in gateway layer capability, which can achieve scaling down to 0, fast automatic scaling.

These characteristics of function calculation make it suitable for Web applications such as Spring Boot. With functional computing, developers only need to focus on the implementation of SpringBoot application logic, and do not bother with the construction, deployment, monitoring and other work of the application environment.

Mall Application Serverless Architecture overview

Mall is a very standard 3-tier architecture Web application that can be easily converted to a Serverless architecture, as shown below. Because the function calculation has a built-in gateway service that automatically pulls up the instance and runs the application, the developer only needs to upload the application code.

The application instance runs on a functional computing platform and can freely access other services in the same way as MySQL, Redis, and RabbitMQ.

Function computation has log collection and presentation capabilities built in. Developers specify LogStore of Ali Cloud log service for function calculation. Logs dialed to standard output will be automatically collected to log service for query and display. Developers can also post logs to their own log processing system, but some additional configuration is required. In this example (see ali Cloud logging service website at the end of this article), we will use Ali Cloud logging service to process application logs.

Functional computing also provides a set of tools to help developers publish applications through the Jenkins CICD tool. We’ll show you more in a future article.

Run Spring Boot on the functional computing platform

Before demonstrating the running of Web applications on Ali Cloud function computing platform, I would like to introduce the following concepts:

service

The service resources calculated by the function correspond to microservices. You can create multiple functions within a service that share service-level configurations, including logging, permissions, VPC network access configurations, and so on. Typically, developers design microservice architectures based on business scenarios, creating functionally computed services for each microservice. Microservices can then be turned into more fine-grained functions as required. For example, if some logic is computationally intensive, it can be split into another function with a different instance specification configured to meet the performance requirements and optimize the cost. According to the concept of microservices, the number of functions in a service should not be too large.

function

Functions are the basic unit for running developer code. Functions can be very fine-grained, for example, for one API, or coarser, for a set of apis. Different functions are configured with different instance specifications. Function computation provides runtimes for various languages, as well as custom Runtime/Custom Container and language-independent runtimes. If you are just evaluating the implementation snippets with functions, you can use the runtime of the relevant language. In our scenario, we choose the Custom Container runtime because we want to seamlessly migrate the SpringBoot application. Mall project already supports automatic packaging of Mall application as container image, so you only need to upload the image to Ali Cloud container image warehouse and specify relevant information on the function.

HTTP trigger

After configuring HTTP triggers for a function, the function can be invoked as an HTTP request. The Serverless Devs tool will generate test domains for HTTP triggers so developers can easily debug and run Web applications.

By now, you have a basic understanding of Mall application architecture and the Serverless platform. At the same time next week, we will explain how to deploy the Mall application to a functional computing platform in Spring Boot on FC – Deployment.

A link to the

1) SpringBoot: https://spring.io/projects/spring-boot

2) Mall:https://github.com/macrozheng/mall

3) function calculation: https://help.aliyun.com/product/50980.html

4) ali cloud log service: https://help.aliyun.com/product/28958.html

5) services: https://help.aliyun.com/document_detail/74925.htm

6) function: https://help.aliyun.com/document_detail/52077.html

7) HTTP trigger overview: https://help.aliyun.com/document_detail/71229.html

8) Serverless Devs: http://www.serverless-devs.com/

Click here for more information on function calculations!