preface

Serverless is also newly emerging. By chance, I saw Serverless on a technical website, and I thought its concept was quite good. Serverless means no maintenance, not completely removing the server, but using public cloud resources, so that there is no need to care about the running status of the server. Whether they are working, whether the application is running properly, etc. Serverless means you don’t care about operations and maintenance. Serverless connotation is the encapsulation of all the underlying resources and operational work, let developers focus on business logic, obviously its technical prospect is very good, so I think we also need to understand and pay attention to it, after all, this thing for the front-end is great, this is also our front end developers a wave of unprecedented opportunities, Enjoy the fun of cloud development, and for small applications he has little to lose.

First, the concept and characteristics of Serverless

Serverless is a relatively abstract concept, because it contains a lot of information, serverless deeply embodies the concept of modern cloud, here I want to give you a summary of the meaning of two:

  1. Narrow Serverless (most common) = Serverless Computing Architecture = FaaS Architecture = Trigger (event-driven) + FaaS (function as a service) + BaaS (back-end as a service, persistent or third party services) = FaaS + BaaS.

  2. Serverless = Server O&M free = Cloud services with Serverless features

To put it more simply, Serverless means that the server-side logic is implemented by the developer, runs in a stateless computing container, is triggered by events, is completely managed by a third party, and its business-level state is stored in a database or other medium. (compared with the current application of traditional mode), it has four main characteristics:

  1. Event-driven —- function in FaaS platform, need through a series of events to drive function execution;

  2. Stateless —- Because each function execution may use a different container, memory or data cannot be shared. If you want to share data, you can only do so through third-party services.

  3. No operation and maintenance —- use serverless we do not need to care about the server, also do not need to care about operation and maintenance, which is the core of serverless thought;

  4. Low cost —- It is very low cost to use Serverless because we only pay for each function run. If the function does not run, it costs nothing and does not waste excessive server resources.

  5. Automatic elastic scaling: According to the actual number of events or requests, the cloud function automatically elastic appropriate processing instances to bear the actual volume of services. When there are no events or requests, no instances run and no resources are occupied.

Serverless Common services and solutions

At present, I only use the Serverless framework of Tencent Cloud to simply build applications and simply operate the Fun command line tool of Ali Cloud, and also simply use function calculation on the official website of Ali Cloud. Enjoy a quick construction and deployment of serverless application pleasure, small program application layer cloud development is also the use of the concept of Serverless, for simple learning this development mode I think it is probably enough, the most practical point is usually their own play things this is really save money and effort. The comparison below shows the price of each service provider.

Application scenarios of Serverless

In fact, some advantages and characteristics of Serverless are mentioned, but I think the most concerned point is its application scenarios, which scenarios are suitable for this mode?

I have just listed some common practical scenarios. I have made a demo of serverless scenarios. There are many more serverless scenarios.

FaaS and BaaS

FaaS, function as a service, also known as Serverless Computing, allows you to create, use, and destroy a function anytime, anywhere.

You can think about how a function normally works: it needs to be loaded from code into memory, instantiated, and then executed when called by another function. In FaaS, too, functions need to be instantiated and then called by triggers or other functions. The biggest difference is in the Runtime, the context of the function, the context in which the function is executed.

The FaaS Runtime is pre-set, and the functions and resources loaded in the Runtime are provided by the cloud service provider, which we can use but cannot control. The FaaS Runtime is temporary. After the function is called, the temporary Runtime is destroyed with the function. After the FaaS function is called, the cloud service will destroy the instance and reclaim the resources, so FaaS recommends stateless functions. To front-end engineers, this is probably straightforward: functions are Immutable. To put it simply, a function that takes a fixed argument must return a fixed result.

In MVC architecture, an HTTP data request will correspond to a Control function, and we can replace the Control function with a FaaS function. When the number of HTTP data requests is large, the FaaS function automatically expands the number of multiple instances and runs simultaneously. When the number of HTTP data requests is small, the capacity is automatically reduced. When there are no HTTP data requests, it is also scaled down to 0 instances to save money.

How does FaaS work

What is the biggest advantage of FaaS

In fact, the biggest difference between FaaS and application hosted PaaS is resource utilization, which is also the biggest innovation of FaaS. The application instance of FaaS can be scaled down to zero, while the application hosted PaaS platform must maintain at least one server or container. Is a new managed environment for running code. In the “Hello World” example above, the actual server usage is 0 before the function is called for the first time. Because the function service is not triggered by an HTTP event to start the function instance until the user’s first HTTP data request comes in. That is, when there is no user request, the function service does not have any function instances and therefore does not occupy any server resources. The process of creating an application instance usually takes tens of seconds. In order to ensure the availability of your service, you must maintain at least one server running your application instance at all times. However, FaaS is like a voice-activated light, which can be turned on quickly when there are people and turned off when there are no people. The most critical point is the fast start feature of FaaS. Cold start means that the function call link contains code download, start function instance container, runtime initialization, user code initialization and so on

To sum up, there are three main characteristics of FaaS:

  1. Pure FaaS application call link is composed of function trigger, function service and function code, which replace the traditional server operation and maintenance load balancer & reverse proxy, server & application running environment and application code deployment respectively

  2. Compared with the traditional application hosted PaaS platform, the biggest difference of FaaS application is that FaaS application can be scaled down to 0 and can be started at the arrival of events at a very fast speed. Node.js functions can even be started and executed at 100ms

  3. FaaS is designed to sacrifice user control and application scenarios to simplify the code model and further improve resource utilization through a hierarchical structure, which is the main reason why FaaS cold start times are so short. You can think of FaaS as a 3-tier structure: the container layer is like the Windows operating system; The Runtime is like the Stormwind player in Windows; Your code is like a movie on a USB stick.

BaaS (Backend as a Service)

BaaS is actually a collection, which refers to the back-end services with high availability, elasticity and no operation and maintenance. The Model layer in MVC architecture needs to be solved with BaaS. Public services manage our data for us, and ServerLess’s philosophy is to serve everything. My initial feeling is to bring you one step closer to the back end. This is usually done one API after another by calling the back end or the program logic already implemented by someone else, such as the authentication service Auth0. These BaaS are usually used to manage data, cloud databases provided by cloud service providers, and various other databases and storage services. It has two modes, one is API mode, which lets developers extend the code themselves; The other is SDK mode, the official SDK of Ali Cloud OSS storage, and Autonavi…