Serverless is a hot technology at present, and is considered as the future direction of cloud computing development. It has many advantages such as free operation and maintenance, reduced development cost, automatic expansion on demand, etc. Especially in the front-end development area, using Node to develop cloud functions allows front-end engineers to focus more on business logic and realize the transition from full-stack engineers. However, the existing development mode, tools and scaffolding have been standardized and streamlined, and the stock business is running stably online. How to integrate Serverless into the existing development mode and tools? How to combine Serverless with current services? This article will attempt to provide an answer.
The content of this article is compiled from the speech by Wang Junjie, technology expert of Tencent Serverless, at GMTC 2019 Shenzhen station.
Front-end and Serverless indissoluble relationship
There are a lot of articles and tutorials about Serverless in different ways. Today we’ll start by reviewing three questions:
- What exactly is Serverless?
- Is Serverless equal to FaaS plus BaaS?
- What are we talking about FaaS?
A March 2019 paper from the University of California, Berkeley, called Cloud Programming Simplified: A Berkeley View on Serverless Computing
Put simply,serverless computing = FaaS + BaaS.
Simple to understand, Faas+BaaS is an implementation of Serverless, which is also a mainstream understanding of Serverless. So what’s the real concept of Serverless? At the core of the abstract, we can see the following paragraph, which speaks the true meaning of Serverless:
The main idea is:
“Serverless Computing encapsulates almost all of the underlying resource management and system operations, making it easier for developers to use the cloud infrastructure. It provides a way to greatly simplify programming based on cloud services, like the transition from assembly language to high-level programming language.”
Here is a very vivid example:
Assembly Language to high-level programming Languages.
“The change Serverless brings to cloud computing is the equivalent of moving from assembly language to high-level language.” Assembly language, computer students have understood. Write assembly, first need to understand the structure of the CPU, know adder, register, need to manage their own memory, IO devices and other low-level resources. But that’s not the purpose of the developer. The developer should be business oriented. The advantage of a high-level language is that it provides capabilities and frameworks that allow developers to focus on getting the business done faster, rather than wasting energy on low-level resource management.
Serverless encapsulates all the underlying resources and operations, allowing developers to focus on the business logic.
After understanding Serverless, let’s talk about the nature of FaaS (Function as a Service). In short, FaaS is the most fine-grained distribution of computing power to date. Let’s understand what that means first.
When we talk about applied computer science, there are three dimensions: “power, algorithm, data”. There are two directions in “computing power” : first, how to make computing power stronger and make the CPU run faster; The second is how to make the calculation power distribution more reasonable. Traditional computer, from single-task real-time operating system to multi-task time-sharing operating system, is to solve the problem of computing power distribution. The original intention of cloud computing and to solve the problem, but also to solve the rationalization of huge computing power resources. What is the granularity of cloud computing power distribution?
The answer is virtual machines.
What is the granularity of the allocation that is a little bit lower than the machine?
The answer is the container.
What’s the next level down from the container?
The answer is a function.
The earliest distribution of computing power was physical machines in units, followed by virtual machines and containers. This process of computing power distribution refinement is basically the process of cloud computing development. Now a function can be used as a computing unit on the cloud, and resources can be allocated once for each business execution, without which there is no resource allocation. Therefore, FaaS is a function (business) granularity of computing power distribution.
Once we understand what Serverless and FaaS mean, let’s talk about how it all relates to the front end.
With the popularity of Node, front-end engineers have been hoping to return to the role of Web engineers, full-stack engineers have been mentioned in various occasions and articles, and big front-end organizational structures have become a hot topic in recent years.
First, from the perspective of front end engineers themselves, they hope to expand their business scope, so as to have career development. Only doing front end display related things, can not touch the core business, and the value can not be displayed.
Second, from the perspective of the organization or technology leader, more attention will be paid to the contribution of technology to the business, the overall execution efficiency of the team, quality control, role cooperation and other issues. The development model of big front end will improve the iterative efficiency of business.
- JavasScript is used on both the front end and the back end, and the technology stack is uniform. From writing code, to compiling, packaging, scaffolding, componentization, package management, and CICD, it is not a problem to adopt the same set.
- Client Side JavaScript and Server Side JavaScript themselves have a lot of reusable code, such as CSR and SSR solutions for isomorphic code in the industry today.
- We will optimize the organizational structure of R&D. The development mode of the big front end makes interface definition, interface joint debugging, environment simulation and so on, which used to require the cooperation of engineers of two different technical capability stacks, become the mode that engineers of the same technical capability stack complete independently, so that the cost of communication and promotion can be reduced to the minimum.
It’s a nice idea, but to be honest, it hasn’t been very smooth. In my opinion, the main reason is the understanding of full-stack. Google full-stack has many images, most of which look like this:
This understanding is built on the business function realization level, as if with the front-end + back-end + database, the basic business can be made. The reality is often quite different! The full-stack architecture that supports services can be divided into at least four layers.
- The first layer is the core business logic, front and back end functions, APIS, data;
- The second layer is business architecture, including application framework, technical architecture, database, etc.
- Layer 3: Service operation and maintenance (O&M), including logging, alarm monitoring, scalability, and load balancing.
- Layer 4: The underlying architecture, including computing resources, system and network security, and disaster recovery.
The higher up you go, the higher the drive for business value because of the focus on business logic; The lower the level, the more difficult the technology is, and the higher the requirement for the technical ability of the personnel. Continuing the analysis, we can find that:
- Layer 1: What full-stack engineers want to do
- Layers 2 to 4: Problems that Serverless can solve
With Serverless, front-end engineers only need to focus on the core business logic, while the underlying technical architecture, computing resources, stability, and system operation and maintenance can be fully supported by Serverless. That is, from the front end to the true full stack possible. This answers our topic of why Serverless is so tied to the front end.
Basic idea of Serverless front-end engineering
Today’s front-end research and development, components, engineering have better solutions. So the question is, is there a better solution for Serverless development? So should we use a framework or not? Front-end developers love frameworks. Because frameworks solve many problems: code reuse, uniform specifications, lower barriers to entry, focus on business logic, community benefits, ease of maintenance, increased efficiency…… Many benefits like a cross talk guankou.
So what does a good Serverless framework look like? I think there are two things that need to be met.
- componentization
The component mechanism is used to organize and manage the code by taking business functions as the unit. It can be reused within the business, across businesses or across companies to achieve the purpose of easy maintenance and efficiency improvement. There are many benefits, which will not be described here.
- standardized
For developers to provide a standard set of interfaces and usage, masking the differences between the heterogeneous systems of the underlying cloud. Like JQuery or Polyfill, which front-end engineers are familiar with, they don’t have to worry about browser differences. The Serverless framework should do the same.
Principle and implementation of Serverless
The Serverless Framework is one such standardized, componentized Framework. At the bottom, it provides basic support for developers, including development, deployment, debugging and monitoring. These support are encapsulated for the interfaces of cloud vendors, and developers do not need to pay attention to the differences of cloud computing platforms. At the upper level, every business scenario and business framework is encapsulated in a componentized way for better maintenance and reuse.
Serverless Framework is an open source Framework with 34.5K star: github.com/serverless/…
The CLI of the Serverless Framework is called Serverless and provides all functions in the form of command lines.
One important mechanism of the Serverless Framework is the Component mechanism.
Each Component is an NPM module. It uses a YML configuration file that describes how the Component uses and allocates resources on the cloud platform. Above is an architecture diagram of Express Component consisting of the Tencent API Gateway, Tencent SCF, and Tencent PostgreSQL.
Component code structure is clear and follows the NPM Module standard. One feature worth mentioning is that components support nesting. For example, a Serverless full-stack Application includes an Express Component to handle server-side logic and a Website Component to manage static files and resources. These two components, in turn, include their child components.
Serverless Now
After understanding the Serverless Framework infrastructure, I’m going to show you a demo of the Servereless Hexo blog today to give you a feel for the Serverless Framework. This demo was made by one MM of the team. She is not a computer student, nor does she have any code experience, nor has she written front-end JavaScript, so we need her to deploy a static blog using the Serverless Framework and Website components.
In this three-minute video demo, we not only uploaded the Hexo release code, but also applied for and configured the following cloud resources. It shows that our products are very resilient. The so-called elasticity of technology products is that there are many optional configurations, but very few default mandatory items. If you are experienced and technically skilled, give yourself the freedom to write each configuration to get the results you want. On the other hand, if you are a beginner like this MM, you can also get started quickly and use it in a few minutes.
In addition to the Website component, the following diagram shows the components that Serverless Framework now supports, including Node, Python, and PHP frameworks.
If you’re interested in Serverless Express, you can check out this Github site:
Github.com/serverless-…
If you already have an Express project, you can now deploy it to the cloud using the Serverless Framework, which can also be accessed on Github.
- First, install Serverless via NPM.
- Step 2: Install Express and create app.js file.
- The third step is to configure serverless.yml. The simplest configuration is shown on the left with only four lines of code (optional configuration items on the right).
- The fourth step, wechat scan qr code for authorization registration or login, and then execute SLS command (serverless short) for deployment;
- Fifth, use remove to delete the project and clean up the cloud resources.
For front-end developers, you don’t even need to know what the cloud is or what it does. The Serverless Framework does all this for you. In addition to Express.js, Koa and Eggjs are also supported by contributions from community developers.
conclusion
This paper is mainly divided into four points:
- The front end and Serverless are truly inseparable. Only Serverless can truly allow a front end engineer to carry the load and complete a full-stack product.
- The basic idea of Serverless front-end engineering is to do it directly on the cloud function of the cloud manufacturer, or based on the existing Serverless Framework.
- It introduces some principles of Serverless Framework, including the bottom layer to support the cloud vendor interface in a standardized way, and the upper layer to make use of Serverless componenzation to reuse services and improve efficiency.
- Finally, I demonstrated the first Serverless Demo of a girl who had never learned programming.
I’ll end with a photo of Yu Liu, author of Serverless Architecture, on the far right, and Austen Collins, CEO and Founder of Serverless.com, author of the Serverless Framework, in the middle.
I’d like to end today with a quote from him: Serverless is the future of the cloud. Serverless has been a great force for us developers, and we believe Serverless will empower developers in the future. Especially for the end developers, from the role of front-end engineer to the full stack engineer, complete the entire application from 0 to 1.
Serverless Framework 30-day trial plan
We invite you to experience the most convenient way to develop and deploy Serverless. During the trial period, the associated products and services provide free resources and professional technical support to help your business quickly and easily implement Serverless!
For details, see: Serverless Framework Trial Program
One More Thing
What can you do in three seconds? Take a sip of water, read an email, or — deploy an entire Serverless application?
Copy the link to PC browser to access: serverless.cloud.tencent.com/deploy/expr…
3 seconds fast deployment, immediately experience the history of the fastest Serverless HTTP actual combat development!
Portal:
- GitHub: github.com/serverless
- Website: serverless.com
Welcome to: Serverless Chinese, you can experience more about Serverless application development in best practices!