What is serverless computing? | Serverless definition

无服务器计算是一种按需提供后端服务的方法。服务器仍在使用,但是从无服务器的提供商那里获得后端服务的公司是根据使用情况收费的,而不是按固定的带宽或服务器数量收费。

学习目标

阅读本文后,您将能够:

  • 定义无服务器计算
  • 概述使用无服务器架构的优势

复制文章链接

什么是无服务器计算?

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 despite the name serverless, physical servers are still used but developers do not need to be aware of them.

在Web早期,任何想要构建Web应用程序的人都必须拥有运行服务器所需的物理硬件,这是一项繁琐而昂贵的工作。

Then came cloud computing, where fixed numbers of servers or amounts of server space could be rented remotely. Developers and companies who rent these fixed units of server space generally over-purchase to ensure that a spike in traffic or activity will not exceed their monthly limits and break their applications. This means that much of the server space that gets paid for can go to waste. Cloud vendors have introduced auto-scaling models to address the issue, but even with auto-scaling an unwanted spike in activity, such as a DDoS Attack, could end up being very expensive.

无服务器的优势

无服务器计算允许开发人员在灵活的“按需付费”的基础上购买后端服务,这意味着开发人员仅需为使用的服务付费。这就像从每月固定限额的手机数据套餐切换到只为实际使用的每个字节数据收费的套餐一样。

“无服务器”一词在某种程度上具有误导性,因为它仍然有服务器提供这些后端服务,但是所有服务器空间和基础设施问题都由提供商处理。无服务器意味着开发人员可以完全不用担心服务器。

什么是后端服务?前端和后端之间有什么区别?

应用程序开发通常分为两个领域:前端和后端。前端是用户看到并与之交互的应用程序部分,例如视觉设计。后端是用户看不到的部分。其中包括应用程序文件所在的服务器以及持久存储用户数据和业务逻辑的数据库。

应用程序的前端与后端

For example, let’s imagine a website that sells concert tickets. When a user types a website address into the browser window, the browser sends a request to the backend server, which responds with the website data. The user will then see the frontend of the website, which can include content such as text, images, and form fields for the user to fill out. The user can then interact with one of the form fields on the frontend to search for their favorite musical act. When the user clicks on ‘submit’, this will trigger another request to the backend. The backend code checks its database to see if a performer with this name exists, and if so, when they will be playing next, and how many tickets are available. The backend will then pass that data back to the frontend, and the frontend will display the results in a way that makes sense to the user. Similarly, when the user creates an account and enters financial information to buy the tickets, another back-and-forth communication between the frontend and backend will occur.

无服务器计算可以提供什么样的后端服务?

Most serverless providers offer database and storage services to their customers, and many also have Function-as-a-Service (FaaS) platforms, like Cloudflare Workers. FaaS allows developers to execute small pieces of code on the network edge. With FaaS, developers can build a modular architecture, making a codebase that is more scalable without having to spend resources on maintaining the underlying backend. Learn more about FaaS >>

无服务器计算的优势是什么?

  • 降低成本 – 无服务器计算通常具有很高的成本效益,因为传统的后端服务(服务器分配)云提供商经常导致用户为未使用的空间或空闲的 CPU 时间付费。
  • 简化可扩展性 – 使用无服务器架构的开发人员不必担心扩展其代码的策略。无服务器供应商可按需处理所有扩展。
  • 简化后端代码 – 使用 FaaS,开发人员可以创建简单的功能,这些功能独立地执行单个目的,例如进行 API 调用。
  • 加快周转时间 – 无服务器架构可以大大缩短产品上市时间。开发人员无需通过复杂的部署过程实施错误修复和新功能,而是逐个添加和修改代码。

Learn more about the benefits of serverless computing.

How does serverless compare to other cloud backend models?

A couple of technologies that are often conflated with serverless computing are Backend-as-a-Service and Platform-as-a-Service. Although they share similarities, these models do not necessarily meet the requirements of serverless.

Backend-as-a-service (BaaS) is a service model where a cloud provider offers backend services such as data storage, so that developers can focus on writing front-end code. But while serverless applications are event-driven and run on the edge, BaaS applications may not meet either of these requirements. Learn more about BaaS >>

Platform-as-a-service (PaaS) is a model where developers essentially rent all the necessary tools to develop and deploy applications from a cloud provider, including things like operating systems and middleware. However PaaS applications are not as easily scalable as serverless applications. PaaS also don’t necessarily run on the edge and often have a noticeable startup delay that isn’t present in serverless applications. Learn more about PaaS >>

Infrastructure-as-a-service (IaaS) is a catchall term for cloud vendors hosting infrastructure on behalf of their customers. IaaS providers may offer serverless functionality, but the terms are not synonymous. Learn more about IaaS >>

What is next for serverless?

Serverless computing continues to evolve as serverless providers come up with solutions to overcome some of its drawbacks. One of these drawbacks is cold starts.

Typically when a particular serverless function has not been called in a while, the provider shuts down the function to save energy and avoid over-provisioning. The next time a user runs an application that calls that function, the serverless provider will have to spin it up fresh and start hosting that function again. This startup time adds significant latency, which is known as a ‘cold start’.

Once the function is up and running it will be served much more rapidly on subsequent requests (warm starts), but if the function is not requested again for a while, the function will once again go dormant. This means the next user to request that function will experience a cold start. Up until fairly recently, cold starts were considered a necessary trade-off of using serverless functions.

Cloudflare Workers has addressed this problem by spinning up serverless functions in advance, during the TLS handshake. Since Workers functions spin up at the edge in a very short amount of time, even shorter than the time required to complete the handshake, the result is an FaaS platform with zero cold starts. To get started with Cloudflare Workers, see our Developer documentation.

As more and more of the drawbacks of using serverless get addressed and the popularity of edge computing grows, we can expect to see serverless architecture becoming more widespread.