Serverless, that is, no service architecture. It refers to third-party cloud computing providers providing developers with required functionality, such as databases, messaging, and authentication, as a service. The core idea is to let developers focus on building and running applications without having to manage servers.

The Serverless technology can be used in two ways: Function as a Service (Faas) or Backend as a Service (Baas).

advantages

The biggest advantage of Serverless is that it scales automatically and does not need to manage itself.

Before deploying an application, you need to purchase a server, install an operating system, and purchase a domain name. With cloud servers, we don’t have to buy a server and install an operating system. You only need to set up the environment and install the database on the cloud server to deploy the application.

But there’s still a problem. When you get too much traffic, you need to add servers; If the traffic volume is too small, reduce the number of servers. With Serverless, you don’t have to worry about that, and the cloud will manage it all for you. The cloud automatically adjusts the resources you need based on how many visits you get.

disadvantages

When applications are deployed in the cloud and use cloud storage or cloud databases, it may slow down our application access. Because network access is an order of magnitude or two slower than memory and hard drives.

Faas

What is function as a service?

A function is usually used to process some kind of business logic, such as an ABS () function that returns the absolute value of the passed argument. We can host this function to the Faas platform, which provides a container and runs this function. When a function is executed, you only need to provide the parameters required by the function to obtain the result of the function execution without deploying the application.

stateless

The container in which Faas runs functions is stateless, and the last run is independent of the next run. If you need to store state, you need to use cloud storage or a cloud database.

Cold start

The Faas function is reclaimed by the container if it has not been used for a long time. So when a function is called for the first time or has not been used for a long time, the container needs to recreate an instance of that function, a process called cold start that typically takes hundreds of milliseconds.

If there is a cold start, there is a hot start. For example, the container has just called a function and a few moments later a new event is raised. At this point, since the function has not been reclaimed, the original function instance can be reused directly, which is called hot start.

event-driven

Faas functions need to be run by firing events. We can specify different triggers:

  • HTTP trigger
  • Object storage
  • Timing trigger
  • CDN is triggered

.

HTTP triggers, which are triggered by HTTP requests, are the most common.

Low cost, charge on demand

Like the cloud server we buy in the past is generally to take a monthly package, package year billing, even if you buy not to charge. Faas operates on a pay-as-you-go basis, where cloud services charge you based on how much you actually use, not how much you don’t charge (Baas is generally available on a pay-as-you-go basis, or on an annual basis).

It needs to work with Baas

Faas, when used alone, is only suitable for deploying some utility class functions. Because it is stateless, each run may be on a different container, and it does not know the result of the last function run. Therefore, if you want to use Serverless to deploy the entire application, you need to purchase OSS cloud storage or cloud database to provide data storage services (that is, to use with Baas).

Baas

What is backend as a Service?

Suppose you are a front-end and are now developing a website. You can do the front end yourself, but what about the back end? At this point you can use Baas. In other words, you only need to write and maintain front-end pages. Everything else, such as databases, authentication, object storage, and so on, is provided by cloud providers. You just need to call them on the front end through the API to use the required services.

Difference between Faas and Baas

Faas is actually a cloud computing platform where users can host their own written functions. Baas, on the other hand, provides a set of services for users to use, called by the API.

Other differences:

  • Faas is stateless, and Baas is stateless.
  • Faas run functions, written by the developers themselves; Baas is a service and does not require developers to develop it themselves.

It can be said that Faas and Baas are two different things, but they have one thing in common, that is, they do not need to manage the server and resource allocation and collation, so they belong to Serverless.

Ali Cloud Faas practice

Now Ali Cloud, Tencent cloud can experience Faas for free, the following ali cloud as an example to demonstrate how to use Faas.

Open Ali Cloud Serverless, click Open now:

If you do not open the function calculation page, please click the console to search for function calculation:

It will then prompt you to authorize the function, and when the authorization is successful, you can view the function you just created.

The arrow points to an API address that triggers the function you set.

Use the Serverless framework

As you can see from the example above, Faas functions can only be written online, or written in advance and copied to Aliyun. To improve the situation, there are a number of Serverless frameworks that allow you to develop locally and then deploy to Ali Cloud or another cloud.

I recommend the Midway framework, which was developed by Chinese nationals and has a very detailed Documentation in Chinese. Follow the quick instructions in the documentation to successfully deploy functions to Ali Cloud or other clouds.

summary

The biggest advantages of Serverless are flexible capacity expansion and no need to personally manage the server. Even though it has a number of disadvantages, they are negligible relative to the advantages, as the popularity of Serverless technology in recent years has confirmed. At present, Serverless technology still has a lot of development space worth exploring, after all, it is still a “born” new technology.

The resources

  • Is Serverless progressive or regressive?
  • In the Serverless world, we still need state

Get you started with front-end engineering

  1. Technology selection: How to do the technology selection?
  2. Uniform specifications: How do you create specifications and use tools to ensure that they are strictly followed?
  3. Front-end componentization: What is modularization and componentization?
  4. Testing: How do I write unit tests and E2E (end-to-end) tests?
  5. Build tools: What are the build tools? What are the features and advantages?
  6. Automated Deployment: How to automate deployment projects with Jenkins, Github Actions?
  7. Front-end monitoring: explain the principle of front-end monitoring and how to use Sentry to monitor the project.
  8. Performance Optimization (I) : How to detect website performance? What are some useful performance tuning rules?
  9. Performance Optimization (2) : How to detect website performance? What are some useful performance tuning rules?
  10. Refactoring: Why do refactoring? What are the techniques for refactoring?
  11. Microservices: What are microservices? How to set up a microservice project?
  12. Severless: What is Severless? How to use Severless?