Serverless Computing
What Serverless Computing Means
Serverless computing is a cloud execution model in which you deploy small units of code, usually called functions, and the provider runs them only when they are needed. You do not provision, patch or scale the servers that run the code. The name is a little misleading: servers still exist, but you do not manage them.
The most common form is function as a service (FaaS). AWS Lambda, Azure Functions and Google Cloud Functions are examples. Each function is written to handle one task, such as resizing an uploaded image or processing a payment notification.
Serverless is an alternative to packaging an entire application as a container. That choice is compared in serverless vs containers.
How Event Triggers and Automatic Scaling Work
Serverless functions are event-driven. An event, such as an incoming HTTP request, a file uploaded to storage, a message in a queue or a scheduled timer, triggers the function. The platform starts an instance of the function, runs it and returns the result.
Scaling is automatic. If thousands of events arrive at once, the platform can run many copies of the function in parallel, and when the events stop, those copies are removed. A function that receives no events can scale to zero, which means no instance runs and no compute is billed.
Billing is usually based on the number of invocations and the compute time and memory each one uses. This suits workloads that are spiky or idle much of the time. Code that runs continuously at high volume can cost more than it would on a dedicated server.
Limits and Trade-Offs
Serverless platforms impose constraints. Functions are generally stateless, so data that must persist belongs in a database or object storage rather than in the function itself. Each invocation has a maximum run time and memory limit. These limits vary by provider and change over time, so check the current documentation before designing around them.
Long-running processes and workloads that need specific system-level setup are often better suited to other models. Delays that occur when a function starts for the first time are covered in serverless cold starts.
Frequently asked questions
Is serverless computing cheaper than a server?
It can be, for workloads that are occasional or unpredictable, because you pay only when code runs. For a service that receives steady, heavy traffic all day, a reserved server or container is often cheaper per unit of work. Compare your expected usage pattern before deciding.
Does serverless mean there are no servers?
No. Servers run the code, and the provider owns and manages them. The word serverless means that you do not see, provision or maintain those servers. Your responsibility shifts to writing, configuring and monitoring the functions and the events that trigger them.