Serverless computing
Serverless computing is a cloud model in which you provide code as functions that react to events. The platform starts instances as needed, none at all included, and you are billed for the execution.
Serverless computing is an operating model of the cloud: you write functions that react to an event (a request, a message, a time of day), and the platform starts as many instances as there are events at the moment, none at all included. There are still servers; you just do not manage them yourself.
Serverless in Azure
The central service is Azure Functions. Every function has a trigger that starts it, for example an HTTP call, a message in a queue, or a schedule. In .NET, a function app runs in the so-called isolated worker model as a process of its own with its own Program.cs. Dependency injection and middleware work there as in ASP.NET Core.
For hosting, Microsoft recommends the Flex Consumption plan. Like the older Consumption plan, it can scale down to zero instances and bills by execution time. Whoever wants to avoid cold starts can set "always ready" instances, which then run all the time and are billed as well.
What serverless means and what it does not
- Scaling to zero: Without events, no instance runs. That lowers the costs when the load is rare.
- Cold start: The first request after a pause pays the startup time. This is most noticeable with HTTP triggers whose answer someone is waiting for.
- Stateless: An instance can disappear at any time. State belongs in storage, a database, or a queue. For longer workflows, there are Durable Functions.
- Not the same as containers: A container app can scale to zero as well. Serverless describes the billing and scaling model, not the packaging. Azure Functions can also be run in Container Apps.
- Not automatically cheaper: With an evenly high continuous load, a service that runs all the time can be cheaper and more predictable.
The term overlaps with cloud computing in general and often with microservices, but it does not have to come together with them.
An example from the Kladde
The Kladde imports tenders from the EU's public TED interface. In the main course, this runs as a background service that checks regularly. In K3's serverless module, you build the same import a second time as an Azure Function with a schedule trigger and decide at the end which way is the better one for the Kladde. The import fits well: it runs briefly, rarely, and without a user waiting.
In the course
Serverless is the topic in K3, module 3.13 (serverless with Azure Functions): Serverless and the isolated worker model, then triggers and bindings, Durable Functions, and operation with costs. In K4, module 4.11, it is placed as an architectural style in the lesson Event-driven and serverless as architecture.