What exactly is ServerLess?

The concept of Serverless is very popular, but there are few developers who can specify what is Serverless.

In the business development of Cloud Integrals, as cloud integrals is the ISV of various e-commerce platforms, especially Taobao platform, we have made a lot of Small taobao applications, and have the use scenario of ServerLess. And in the future business development, ServerLess mode is also the main way of Taobao small program development.

ServerLess

ServerLess is a combination of the words Server and Less. Server means “service” and Less means “Less, none”. The direct translation is “no server”.

The official definition is as follows: Serverless is the concept of building and running applications that do not require server administration.

My personal understanding of server management is that there is no operation and maintenance work.

ServerLess ServerLess ServerLess ServerLess

Serverless computing is a method of providing backend services on an as-used basis. A Serverless provider allows users to write and deploy code without the hassle of worrying about the underlying infrastructure. A company that gets backend services from a serverless vendor is charged based on their computation and do not have to reserve and pay for a fixed amount of bandwidth or number of servers, as the service is auto-scaling. Note that although called serverless, physical servers are still used but developers do not need to be aware of them.

The Chinese translation reads:

Serverless computing is an approach to providing back-end services on demand. Serverless providers allow users to write and deploy code without worrying about the underlying infrastructure. Companies that get back-end services from a serverless vendor will calculate fees based on them, rather than having to retain and pay for a fixed amount of bandwidth or number of servers because the service scales automatically. Note that despite being called serverless, physical servers are still used, but developers do not need to know about them.

Some community related concepts

Understanding the above concepts is not enough, we also need to understand the community, some of the surrounding concepts for ServerLess.

For example, some people say ServerLess development is cloud function development? We’re not going to solve it, but we’re going to look at some concepts.

  1. Faas, function as a service, is also called cloud function. As a component/service, function provides users with a kind of capability. These capabilities include: Web services, web sites.

  2. Baas, backed as a service, provides boundary services for mobile applications, including back-end services provided by back-end development middleware, resource pool, message notification, LBS, and surrounding SDK.

    Does Faas === ServerLess? From the developer’s point of view, we use the ServerLess model, which in most cases is just writing cloud functions, but the cloud function is just an event, and we drive something else in the cloud function, like looking up the database, getting the results, and then returning them to the user. Where you interact with a database, or with a third party, you can’t call it Faas. Those that provide a database for application development, caching, and so on, should be called Baas.

    So, in most cases, it should be ServerLess = Faas + Baas;

  3. Laas, infrastructure as a service, refers to basic software and hardware infrastructure services, including Docker, K8S, etc. This is the cornerstone of ServerLess. All of our imagination space ServerLess applications are based on this premise to be implemented.

    In addition, there are other concepts such as Paas, Saas, and so on.

Look at ServerLess technology from the perspective of operation and maintenance

Speaking of Serverless, we have to look at Serverless technology from the perspective of operation and maintenance. We can simply divide the operation and maintenance work into three stages, and in each stage, the operation and maintenance work is completely different.

  1. The initial operation and maintenance mode

    At this stage, we need to be familiar with a large number of work required components, such as server, Nginx, Tomcat, mysql, Redis, MQ, Kafka, operation and maintenance work is very complex, need to put a project, according to the different types of projects, the required components are different, the deployment of a project to the server.

    Of course, that’s not all. The same code depends on different environments, some of which run on Windows and some of which run on Linux. The same code, depending on the third-party version of the library is inconsistent, can also lead to a variety of problems with the code.

  2. Docker technology

    What is the solution to the operation and maintenance work up there? Yes, it’s Docker. The essence of Docker is to unify the differences of hardware environment. Docker is a standard Linux system, which can run on any server (Linux and Windows), but it provides a unified environment for software to run and deploys a service. We can choose to build different image environments. The so-called image is to fix the dependent software environment. Node8, Java1.8, some version of redis, etc.

    The advantage is that as long as a running environment is determined, it is very convenient to expand the capacity of the machine and manage the arrangement of resources. K8s, is a tool for docker orchestration governance.

    At this time, the operation and maintenance work efficiency is improved, and the labor cost is also saved.

  3. ServerLess

    ServerLess based service providers, in fact, only the big companies, just playing on the stage, these large server vendors, the operations of the work, have done very well, but also provides a variety of convenient for developers using the surrounding ecosystem, operations that developers do not have to focus on server deployment related knowledge, focus solely on the current application development.

    That is to say, in the ideal Serverless development mode, we do an application and do not need operation and maintenance work.

Taobao open platform -Serverless development

Taobao ServerLess development, also known as cloud service, front-end development engineer, only need in Taobao developer tools, can complete a front-end, database, interface fully equipped with business applications.

Specific development details, not in the article to discuss the content, we focus on the need to understand, Taobao small program ServerLess development, which modules in the end. And the relationships between these modules.

Taobao Developer Tools

The main role is to carry out small program development, cloud service development. And the uploads of these apps, the associations of these apps, and so on.

Small program development, mainly to follow taobao open background, business application development specifications on the line. It has associated syntax rules, file structure, and so on.

Cloud Applications (ServerLess)

A standard applets application, if developed using the cloud application pattern, would have a directory structure like this.

Client part: The part of the applet. Follow the syntax of the applet.

Server part: the part that provides cloud services, that is, one cloud function at a time, the ability to provide various services.

A standard cloud function code is as follows:

exports.main = async (context) => {
  const cloud = context.cloud;
  const collectionName = 'users';
  try {
    // Cloud is the SDK that provides basic database operations, where "Users" is the database that needs to be connected, the function of this operation is to query all the data in the Users table.
    const res = await cloud.db.collection(collectionName).aggregate([{
      $match: {}}]);return {
      code: 200.msg: 'ok'.data: res
    };
  } catch (e) {
    console.log('Add failed! In the IDE, create the collection Users (${context.env}Environment) `);
    returne; }};Copy the code

We can see that the cloud function provides a simple list query capability.

Cloud functions can be published directly, and you can choose to publish in different environments: test, pre-release, online, etc.

In taobao developer tool, we can see visually what cloud functions have been published, as shown in the picture below:

The database

Cloud functions will operate on the database, such as data increase, deletion, change and check, and other functions. Our ServerLess development does not mean that there is no real data storage, but it will be stored in the cloud servers of various manufacturers in essence, but we do not need to care about how it is stored. Taobao open platform, to provide us with a visual database table of new, delete, change the ability.

For example, the users table has two endpoints, name and age.

Tencent Cloud -Serverless development

Tencent Cloud ServerLess development, and Taobao small program is very different (as for why, explain later), Tencent cloud it is more to provide a broad solution, it provides a NPM package – ServerLess.

ServerLess, in the world, also has certain standards, Tencent cloud based on the international standards, to achieve its own ServerLess standards to provide its own solutions.

Tips: However, according to my personal thinking, it is very difficult for ServerLess to be unified in the whole industry, because the bottom layer of ServerLess is the cloud server of various manufacturers. The formulation of ServerLess standard is essentially a matter of the proportion of cloud services in the whole market. But obviously, toB services, It's not as easy to dominate as toC, it's more driven by customer relationships and their various needs. Therefore, serverless development is not without its shortcomings. Its great limitations are determined by the split cloud service vendors. Different cloud service vendors are inconsistent in the implementation of serverless standards.Copy the code

According to the document, to use ServerLess of Tencent Cloud, you need to install ServerLess globally.

npm i -g serverless
Copy the code

We then use the SLS command to initialize, develop, publish, and so on a service.

Tencent cloud ServerLess standard, mainly reflected in a file, each Tencent cloud ServerLess project, must have.

serverless.yml

component: website
name: websiteDemo
app: serverless-demo-139616b4

inputs:
  src:
    src: ./src
    index: index.html
    error: index.html
  region: ap-guangzhou
  bucketName: my-website-starter
  protocol: https

Copy the code

Meaning generated by ServerLess

One of the things that people have been thinking about is, what is the frontier of the front end? Now the front end, has long been not the past Web development engineers, he can do small programs, do App, do desktop applications, and even do the server. So what’s the downside of the front end? In fact, the short board of the front end is operation and maintenance ability, service concurrency ability.

The birth of ServerLess itself solves this problem, we do not need to worry about operation and maintenance, deployment, concurrency and other issues. We can really focus on the business. At this point, we shouldn’t call ourselves front-end developers, we should call ourselves application developers/cloud developers. At this time, we do not need operation and maintenance, or even back-end, directly use front-end ServerLess technology to solve all the problems of the enterprise.

The relevant data

ServerLess Chinese version: serverlesscloud.cn/

ServerLess development: cn.serverless.com/