How do you quickly develop, deploy, and turn a great idea into a product when something unexpected comes along? Fast, should be ten thousand changes! Serverless is a hot technology and is considered to be the future direction of cloud computing development. How to use Serverless Framework to achieve fast cloud access? This article is teacher Wang Junjie’s sharing and organizing in “Yunjia Community Salon online”, elaborates the basic ideas, framework principles, component architecture of Serverless cloud, and takes everyone to uncover the mysterious veil of Serverless.

Click this link to see the full replay

Basic concepts of Serverless cloud

Thank you to the Cloud Plus community for organizing this online event on “Technology Resilience” and inviting me to share it with you. I will interpret it from the perspective of Serverless. Serverless is the hot word these days, which translates as “Serverless” in Chinese. Some people think that since it is serverless, it means no longer need operation and maintenance, it is completely pay-as-you-go model…… In fact, these understandings are one-sided, describing only one aspect of Serverless.

From 2014 to 2020, the Google search index for Serverless keyword has been rising day by day, and it has become a very popular technology term. The concept of Pay as you Go — buy as much as you need — was actually proposed back in 2006, but it wasn’t until 2012 that Serverless was first proposed. From 2014 to 2016, large cloud vendors released functional computing related products supporting such a serverless technology.

Tencent also joined in and launched FaaS platform of SCF cloud function in 2017. Based on this FaaS platform, Serverless product developed by wechat small program cloud was released in 2018. In 2019, Tencent Cloud launched Serverless Framework.

1. Calculation power, algorithm and data

So what exactly is Serverless? When it comes to Serverless, many people naturally think of FaaS+BaaS. What is FaaS? As we answer this question, let’s review a few basic concepts in the field of computing.

In the development process of computer application technology, there are three main influencing factors: computing power, algorithm and data. For example, AlphaGo’s victory over human beings means that it has improved performance in computing power, algorithm and data. An algorithm is a process from target to solution, usually a mathematical model or calculation method.

When it comes to cloud computing, it mainly solves the problem of computing power. The development of computing power is mainly from two aspects:

The first is to make computing more powerful, to make the CPU or GPU run faster. From the CPU ladder diagram we can see that all generations of CPUS are constantly refreshing the limit of computing speed.

The second is another development direction of computing power, how to allocate computing power more reasonably. 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 solve the problem, is still the problem of computing power distribution. Build a Cloud, a super-scale computer cluster, which can be provided to different customers as needed to allocate computing resources more rationally.

In the early “bare metal” era without cloud computing, it was very troublesome for everyone to build their own computer room. It was not necessary to prepare a house and buy some machines to install it. Things like water, electricity and fire protection need to be taken into account.

Cloud computing provides virtualization solutions. In the IaaS era, the cost of investment is lower, and virtual machines can be directly purchased and operated. Then came PaaS, where you could use platform services without paying attention to the machine, and now FaaS. As cloud computing has evolved, the cost of manpower and capital has become less and less, essentially because cloud vendors have done more and more for their customers.

2. Serverless with FaaS

I just talked about how cloud computing makes the distribution of computing power more reasonable, and one of the more reasonable manifestations is that the distribution of computing power is getting smaller and smaller.

In the IaaS era, computing resources are allocated to VMS in the granularity. To solve bare-metal and virtualization problems, operating systems and application platforms on these VMS need to be built, operated, and maintained. In the PaaS era, the focus on the operating system and application platform/environment is reduced, and users only need to focus on the application layer implementation, so the granularity of resource allocation becomes the application.

In the era of Serverless and FaaS, the granularity of computing resource allocation becomes smaller and is allocated in the granularity of function by function Funcition (business logic execution).

At the end of the day, FaaS is a distribution granularity of “computation” that is granular to the execution of business code. It’s not code granularity, it’s not virtual machine granularity, it’s not container granularity, it’s function granularity.

So what does Serverless have to do with FaaS? Here is the Berkeley academic view: Serverless Computing is FaaS+BaaS.

This is not a definition, but it is a concrete way to implement Serverless. What does Serverless really mean? In the most important part of this paper, the concept of Serverless is explained. Serverless cloud computing encapsulates almost all of the underlying resource management and system operations, making it easier for developers to use cloud infrastructure.

It provides a way to greatly simplify programming based on cloud services, similar to the transformation from assembly language to high-level language programming.

This metaphor is the punchline. You all know that you can’t learn computer technology without assembly language, you need to know what memory structure looks like, you need to be exposed to the concept of memory location to manipulate files and memory. For high-level languages to put it bluntly, do not need you to pay attention to the bottom of the computer in the end is what, just pay attention to their own business, such as they will abstract your business into different modules, abstract into a number of objects and classes……

Moving this to the cloud computing level, Serverless also does not require you to know what the bottom layer of the cloud is, as long as you fully focus on your business, this is the connotation of Serverless, its essence is the encapsulation and operation of the bottom resources.

3. Prototype to product evolution steps

What is focusing on business logic? Here is an example to illustrate that when you have a good idea and want to make a product, there is actually a gap.

From an idea or a prototype, how can it be turned into a real product? Generally speaking, there are three steps from prototype to product:

The first step is business logic, which includes business processes, interfaces, interactions, data storage, and so on. It’s all about making features and processes, but when you get those features done, you have a prototype, not a product.

The second step is productization. Is it fast? Is the performance available? How about reliability? Do you often get stuck? How about scalability? Is horizontal capacity expansion supported? There are many technical dimensions to consider.

Step 3: Operation and maintenance of product launch. How loaded are the resources? Is the error rate monitored? How does the system log slice and flow? What to do when there is an emergency to expand capacity? Operational work for the business is also required.

The first part is what most engineers do every day. Business functions, process logic, presentation, interaction and data can be well supported by utilizing various front-end and back-end frameworks and engineers’ creativity.

The second part is mainly about architecture. The architecture behind business functions is relatively complex, and many systemic problems need to be considered and solved at the architecture level. For example, is the service business architecture robust enough? Are dependencies between modules reasonable? Is it easy to debug? Are logs and exceptions handled in a unified manner? How to quickly locate faults? Are the code and modules reusable? Can a new person come in and take over quickly? System performance, security, scalability, comprehensibility, and reliability are all addressed at the architecture level.

The third part of the operation and maintenance work is also a complex work. Take capacity expansion as an example, it is a troublesome thing. The biggest problem of capacity expansion is that we do not know when to expand capacity. Unless we can accurately estimate the future capacity, we will be much more calm.

However, the user growth curve of a product is often difficult to accurately estimate, especially when your idea is particularly good and quickly popular in a short period of time. For example, in 2019, there was a very popular app that could change the face of a video AI. As soon as it went live, it quickly became popular across the country – but it was not open that night because of capacity problems. In addition, in the context of Internet +, many traditional industry applications now want to go to the cloud.

The word “cloud” is easy to say, but in reality cloud involves the storage and distribution of cloud computing technologies at all levels, and some new ways of development, deployment and operation. The whole cloud process requires a lot of knowledge and experience, and the time cost is not small. According to the above analysis, we know that there is a long way from an idea to an online product.

4. Full stack technical level from Demo to product

On the other hand, whether front-end development, or back-end development, all want to do full stack development engineers.

At the beginning, only Web engineers played the role. Later, in the Era of Web2.0, more and more presentation and interaction work was moved to the front end, while the back end was more responsible for data processing and business processes, and division of labor also emerged.

But the problem was the overhead of division of labor and collaboration, so everyone wanted one type of engineer who could do the whole thing. This is full stack engineer, but this road, but not as smooth as imagined. The reason lies in the understanding of full-stack. Most online interpretations of full-stack are as follows: If you can handle the front end, the back end and the database, you can become a full-stack developer. But is this really the case? A full stack engineer is far from it!

This understanding is based on the level of business function realization, as if with the front end + back end + database, basic business can be done. The reality is often quite different!

The full-stack architecture that truly supports a business has at least four layers:

The first layer is the core business logic, business processes, front-end presentation, back-end functions, APIS, data, etc.

The second layer is business architecture, including application framework, technical architecture, database and so on.

Layer 3: Service o&M includes logs, alarm monitoring, scalability, and load balancing.

The fourth layer is the underlying architecture, including computing resources, system and network security, and disaster recovery.

Higher up, the drive for business value is higher because of the focus on business logic; The lower the level, the more difficult it is, the higher the requirements for the technical ability of personnel. Further analysis, we can find:

  • Layer 1: Full stack of what engineers want to do
  • Layer 2 to layer 4: Problems that Serverless can solve

With the power of Serverless, engineers still only need to pay attention to the core business logic, while the underlying technical architecture, computing resources, stability, system operation and maintenance can be fully supported by Serverless.

5. Connotation and advantages of Serverless

In the Serverless architecture, just focus on the business core logic. Business logic how to do now, the original language framework, database, etc. can still be used under Serverless. For the underlying architecture of core business logic, including the allocation and management of computing and storage resources, Serverless packages it for you.

In addition, Serverless has an advantage when it comes to billing. Serverless follows the on-demand billing model, charging as much as you use, with no waste of idle resources.

The following figure shows the charging model of Serverless. The yellow area in the figure on the left is the cost paid by the virtual machine, which is a rectangle. The shaded part surrounded by the green curve is the cost of Serverless.

It is worth mentioning that Tencent Cloud released the first Serverless service with 1-millisecond billing granularity in China and even in the world. What does 1-millisecond billing granularity mean?

Here’s an example: Let’s say we buy a 100 yuan mobile data plan and get 100 GIGABytes of mobile data, which seems like 1 yuan for 1 gigabyte of data. But that’s not true, because you’re actually charging 100 yuan for 1 gigabyte, and 1 millisecond is just 1 yuan per gigabyte. The same is true for Serverless service billing. If your application only ran for a few milliseconds, it will also be billed for 100 milliseconds, as is the industry standard. Tencent cloud Serverless by 1 millisecond billing, basically realize the real program used how much, how much cost.

In the actual calculation, the processing time of each request is very short under Web service, far less than 100 milliseconds, so using WebService as an example, Tencent cloud Serverless service can save about 70% of the cost! In addition, Tencent cloud Serverless now has a large number of free trial quota released, the current free trial quota is enough to cover the cost of resources required by the site of 30,000 PV per day.

Serverless and technical stress

Today’s topic is “technical resilience”. What does it mean for engineers, architects, and Ctos?

For engineers, technical resilience is career development. From this perspective, “technological resilience” can be understood as “technological transfer capability”. If you did A, can you only do A? Are your technical skills transferable from A to B, C, or D? Serverless is one of the most fashionable new technologies, and many engineers are rapidly filling up the technology stack on Serverless. If you include the Serverless Technology Stack on your resume, the current point in time is sure to make the interviewer think of you as an engineer who really likes new technology.

What does “technical resilience” mean for architects and technical leaders? Imagine if your boss asks a technical leader if your team has technical resilience. What does that mean? “Technical resilience” refers to the adaptability of team working ability for technical leader. We used to do product A, but now we need to do product B. Can you use the current team and the current technical structure to produce product B quickly? Serverless largely helps the technical team improve this capability. Serverless helps the technical team with all the underlying resource allocation. The technical team doesn’t need to deal with this anymore, just focus on the core business logic, consensus on increased productivity, and flexibility.

What does “technical resilience” mean to a company boss or CTO? At this level, the conclusion is different. For the boss or CTO, “technical resilience” often means a better technology input cost structure.

In terms of cost control, Serverless can save the cost of computing resources by paying on demand as mentioned above, and more importantly, it can change the cost structure of technology investment of the company. Such a better technology investment cost structure can reduce the company’s excessive investment in technology to a certain extent, so that the company can quickly respond to market changes and complete business transformation or transformation with the least silent cost.

To be clear, from an accounting point of view, Serverless changes the company’s cost of technology input from fixed cost to variable cost to some extent.

How do you think about variable costs? For example, if the Marketing Department makes a product advertisement, let’s say it buys a TV advertisement or subway advertisement, and it costs XXXX million yuan a year, which is the fixed cost. We cannot make a complete correspondence between the advertising effect and the customers. Even if a customer does not bring, or brings many customers, the advertising cost is fixed. Pay-per-performance (CPA) advertising, on the other hand, is a variable cost, which can be divided into the cost of each sale, which is understood as acquiring a customer and paying for an advertisement. This is the variable cost involved in the sales process, as well as the variable cost structure of the company’s technology input.

If the technology investment can be paid for the number of times the business is executed, the size of the cost will vary with the size of the business, and it will be very manageable. The cost structure of technology input also has a great influence on the decision of technology upgrading and transformation. If the company’s early technical input adopts the technology selection bound by some factors, such as the self-built computer room and the scheme of using physical machines. When companies upgrade their technology architecture, there is resistance because of the silent cost. Therefore, when considering the cost structure of technology input, the company should also focus on the “technology resilience” factor.

3. Principle of Serverless framework

1. Why is such a framework needed?

The essence of Serverless is to help customers hide the underlying resources and management work, so that you focus on the business logic, but the specific implementation is still FaaS+BaaS such a structure, FaaS is a cloud function, BaaS is a variety of cloud services.

For a developer who is used to developing business code under a familiar IDE and framework, being told to refactor the business code using Function means a lot of money in itself. For the development team, the development team needs to pay attention to the underlying cloud services, apis, cloud functions, databases, cloud storage and various cloud services. In fact, most of the administrative state of these cloud services is confusing and difficult to maintain. Because there are many cloud services, there is no standard between different cloud vendors, and the implementation style and usage of each service is also different.

So we have to ask: is there a framework to solve this problem? I think the answer is yes, for example almost all front-end and back-end development is now based on frameworks, and writing apps in pure native code is not team friendly. Frameworks have a lot of benefits, including code reuse, uniform specifications, focus on business logic, added value to the community, ease of maintaining your own code, frameworks can help you do a lot of things and increase productivity.

2. What framework is suitable for Serverless?

So what would an ideal Serverless framework look like? I think there are two requirements that need to be met.

(1) Componentization

Using the component mechanism, code can be organized and managed in terms of business functions, so that it can be reused within the business, across teams, and even across the entire ecosystem for better maintenance. Not only is it easy to maintain, it also improves efficiency. We believe that a good Serverless framework is a componentized framework that improves efficiency.

(2) Standardization

To provide developers with a standard set of interfaces and usage, shielding the differences between heterogeneous systems in the underlying cloud. Like JQuery or Polyfill, which front-end engineers are familiar with, they don’t care about browser differences. The Serverless framework should do the same.

3. ServerlessFramework

The ServerlessFramework is such a componentized, standardized Serverless application development product. It provides a very standard developer interface, including development, deployment, debugging, monitoring, and complete isolation from the underlying heterogeneous cloud vendors. You see a completely developer-oriented view of the original development.

On the componentization side, the Serverless Framework provides different components based on the dimensions of the business. For example, it provides an Expres component that you can use to migrate your original application to Serverless if it was developed based on Express. At the same time, the framework provides full lifecycle management and support from r&d to launch, including development, debugging, co-commissioning, testing, deployment, the entire DevOps process is supported by the framework.

This framework also provides a convenient command line tool CLI for you to use, time relations, not to repeat.

4. Serverless component architecture

Today I’m going to take a closer look at the core of the Serverless Framework, the component architecture. Once you understand the component architecture, you can understand exactly how the framework works.

What is the Serverless Components component? NPM module! This module uses YAML files for configuration. The configuration describes what resources you need from the cloud vendor, and uses and allocates the underlying cloud resources through description.

It is important to note that simple components can be combined to form more complex components through composition relationships. The Express Component, shown in the figure below, is an advanced Component that combines API gateways, SCF cloud functions, and some databases.

Basic components can be integrated into higher-order components. So what are the components needed for a full stack application?

In the example below, Full Stack Application takes Express Component as the server framework and Website Component as the client static Website, completing the front-end and back-end architecture.

Serverless Framework now supports most of the community Framework components. The following figure lists some of the more commonly used components, but more are supported.

Five, Serverless practice

1. Configure and deploy Serverless

If you need to use Serverless, there are only three steps: Step 1: Install Serverless CLI step 2: Configure YAML Step 3: Deploy Appliction online

The Serverless Framework is a very flexible Framework. Flexibility, if you are a senior developer, provides a lot of custom items for you to configure, such as: the region to deploy the code, custom domain name, whether to use HTTPS service, etc., can be configured. Conversely, if you are a beginner, you can use the component’s default configuration, serverless.yml, without changing a single line of code. Take express.js as an example:

As you can see, the simplest configuration of the Express component is only four lines, and only two lines are meaningful. One line indicates that the Tencent Express component is to be used. The second line indicates that the region to be deployed is Shanghai.

As you can see from the image above, there are a number of configuration options available for Express if you need to do very deep customizations, including memory management and timeout management. Finally, SLS (serverless) command was used to complete the upper cloud deployment in tens of seconds.

This cloud deployment is not a simple upload code, it completes the allocation of all cloud underlying resources, cloud functions, storage, database, CDN, security configuration, as well as the required monitoring configuration, alarm configuration these things are all done. This is already an online production application. If you need to remove, you can use SLS Remove to remove all cloud resources in one click.

2. Standardized development mode display of Serverless Framework

Now I’ll show you what the Serverless Framework does to standardize the development pattern.

(1) Engineering

We have partnered with CODING platform to create DevOps to improve r&d performance. If you are a CODING customer, it is now very convenient to use Serverless.

(2) the Dashboard

The Dashboard product, which will be available soon, will help users manage their apps, allowing them to see how many resources they use in the cloud, among other things.

(3) Operation and maintenance

How do I view monitoring information, alarms, and logs? How do I locate problems? Dashboard also has a lot of data related to operation and maintenance. Therefore, Serverless is not without O&M, but does O&M in a more advanced way, making o&M work closer to the business.

3. Learning resource benefits

Finally, we provide some learning resources, which is a summary of carefully prepared learning resources for you, including some official documents, components, tutorials and so on. If you are interested in Serverless, these resources are for you.

Serverless is the future of cloud computing. Serverless brings a lot of empowerment to developers. I believe Serverless will develop very well in the future.

Six, Q&A

Q: Is there no need to use GraphQL with Serverless?

A: There are two levels. GraphQL is A more user-friendly and convenient way to manipulate A database. Serverless plus GraphQL is more developer-friendly and easier to write applications. In addition, ServerlessDB will be released soon, please pay attention.

Q: Express runs as a server, does it start and then work?

A: Yes. However, the Serverless Component and cloud functions will help you solve this problem. Developing Express applications in Serverless mode will not be aware of these. In this case, developers need to focus only on the business logic of the Express framework and not too much on Express service startup issues.

Q: How does it work with applets?

A: Please refer to the product of wechat applets cloud development. It is A very good development method of wechat applets Serverless.

Q: You need to select a region for deployment, such as Shanghai. Is there a way to access it nearby?

A: The problem of nearby access of resources is essentially solved by CDN. Currently, the Serverless Website component already supports the configuration that can add CDN by default. If you choose to use CDN, Serverless will automatically configure it for you.

Q: Will traditional backend technologies still be useful in the future?

A: Of course! Serverless technology will make back-end r&d more focused on back-end business logic, data processing and flow, scheduling, policies, algorithms, transaction management, service governance, etc., strong business contribution. A large part of back-end development today is spent dealing with a variety of “chores.” Sometimes some system abnormalities need to be paid attention to, the peak flow of CPU idle decrease also need to pay attention to, these products are really “dirty and tired”, Serverless technology, back-end students can work more comfortably.

Q: Can Tencent cloud applications be used directly now?

A: you can use as A page provides A community website and address, I also provide you with A resource aggregation page: china.serverless.com/blog/2020-0…

Q: Serverless basic stands for stateless, right?

A: Cloud functions are currently stateless, but Serverless is not equal to cloud functions. Cloud functions are just A way of allocating computing resources, which are allocated in granularity for each execution of business resources. Serverless stateful can be implemented using some database or session service.

Q: Is instantaneous high concurrency seckill appropriate?

A: It fits perfectly. In seckill cases, only those periods are high in requests, and resource utilization may drop off immediately after seckill, so using Serverless technology is a good fit.

Q: Does the cloud function of wechat small program use Tencent Cloud function?

A: That’s right, yes. Tencent Cloud function provides the underlying computing resources for the development of wechat small program cloud.

Q: If my server starts up and takes about ten seconds to load various complex configurations, is Serverless not suitable for this scenario? In the case of API gateway triggers, is Serverless only recommended for short requests?

A: No. This is a good and in-depth question because you are concerned about the performance of the cloud function cold start. The optimization of cold start has two directions. One is to optimize the startup speed itself. Now Tencent Yunyun Function has achieved the level of 100 milliseconds in cold start based on lightweight VIRTUAL machine technology. The second solution is to provide some preheated resources through the resource pool. Tencent Yunyun function always has some pre-allocated instance resources.

Q: Do I need to warm up the SEC?

A: For customers, there is no need to pay attention to the warm-up process. Although there is no such thing as an endless supply of resources, in theory or in practice, it can be met at any time in terms of the magnitude of requests and resource requirements of the average user.

Q: Is non-service more reflected in FaaS? Many functional services can also be addressed by existing components. Functional services do not feel significant in general business scenarios?

A: I understand your question. Maybe you want to reorganize and reconstruct the business scenario in A functional way. Functions are computational resources that can be used in very flexible ways. Some developers use the granularity of functions directly to organize business logic, and it’s certainly ok to do so. However, the Serverless Framework advocates building business code based on traditional frameworks and services instead of focusing on functions as computing resources. So let’s write it the same way we did before. Serverless takes care of the underlying resources that need attention.

Q: Can Serverless be used by any developer to reduce workload?

A: I couldn’t agree with you more. Among the developers I contact, there are front-end, back-end, and full stack, using Serverless can reduce a lot of work. Serverless belongs to every developer.

The lecturer introduction

Wang Junjie, Tencent Cloud Serverless technology expert, has more than ten years of Internet research and development experience. Responsible for the application scheme design of Tencent cloud Serverless product technology in full-stack development, mainly studying how to combine Serverless with traditional development language and development framework to promote Serverless full-stack development and traditional business Serverless on the cloud. And Serverless development of Cloud Native App.

Pay attention to yunjia community public account, reply “online salon”, you can get the teacher’s speech PPT~