Lesson 6 of 6 Cloud Computing Concepts

Understanding Serverless Computing

This lesson explains what serverless computing is, how an event-driven execution flows, and the Azure serverless services, Azure Functions and Azure Logic Apps.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the characteristics of serverless computing.
  • Distinguish Azure Functions from Azure Logic Apps.
  • Identify scenarios that suit serverless computing.

What serverless means

Serverless does not mean that there are no servers. It means that the customer never provisions, sees or manages them. The cloud provider allocates compute resources only when the code needs to run, scales out automatically to handle more events, scales in again when demand falls, and in many plans scales to zero when nothing is happening. The customer is responsible only for the code or workflow and its data, which makes serverless a form of platform as a service.

Serverless solutions are event-driven. Each execution is started by a trigger, such as an HTTP request, a timer, a new message in a queue, a new file in Blob Storage or a change in a database. Billing reflects that model: customers pay for the number of executions and the compute resources used while the code runs, rather than for servers that are allocated all the time.

How a serverless execution flows

The following sequence shows what happens when an event arrives at a serverless function, for example when a customer uploads a photo that must be resized.

  1. An event occurs

    A photo is uploaded to a Blob Storage container.

  2. The trigger fires

    The platform detects the new blob and starts the function that is bound to it.

  3. Compute is allocated

    Azure runs the function on infrastructure it manages, adding instances if many photos arrive at once.

  4. The code runs

    The function creates a thumbnail and writes it to another container.

  5. Resources are released

    When no events remain, instances are removed; billing stops when there is no work.

The following diagram shows the steps from an event to released resources.

How a serverless execution flows. An event occurs, such as a photo uploaded to Blob Storage. The trigger fires and the platform starts the function bound to it. Azure allocates compute on infrastructure it manages, adding instances if many events arrive at once. The code runs, for example creating a thumbnail. When no events remain, the instances are removed and billing stops.
Compute exists only while there is work.
Put in order

From event to release

Exam skills 1.1.7

Put the stages of a serverless execution in order.

Log in to try this activity Interactive activities are free with an account.

Azure serverless services

Azure Functions runs small pieces of code, called functions, in languages such as C#, JavaScript, Python, Java and PowerShell. Functions are stateless by default, although Durable Functions add stateful workflows. The Flex Consumption plan is Microsoft's recommended serverless hosting plan: it scales to zero and bills for executions and resources used, with options for always-ready instances. Other plans, such as Premium and Dedicated (App Service) plans, keep instances running for predictable performance.

Azure Logic Apps runs automated workflows designed in a visual designer, with hundreds of prebuilt connectors for services such as Office 365, Salesforce, SQL Server and SAP. It suits integration and business process automation, such as sending an approval email when a file is added and updating a database when it is approved, without writing much code. The difference is that Azure Functions is code-first, while Logic Apps is designer-first.

Sort into groups

Functions or Logic Apps?

Exam skills 1.1.7

Decide whether each requirement suits Azure Functions or Azure Logic Apps.

Log in to try this activity Interactive activities are free with an account.

When serverless fits

Serverless suits workloads that are event-driven, short-running and variable or unpredictable: processing uploads, reacting to messages, running scheduled tasks, building lightweight APIs and connecting services. Its benefits are no infrastructure management, automatic scaling and paying only for execution. It is less suitable for long-running processes and for steady, high-throughput workloads that run all the time, which may be cheaper on dedicated resources, and an application that has scaled to zero can take a moment to start, known as a cold start.

Select all that apply

Good serverless candidates

Exam skills 1.1.7

Pick the workloads that suit a serverless design.

Log in to try this activity Interactive activities are free with an account.
Worked example

Choosing serverless

A small company receives order files from partners at irregular times, sometimes dozens in an hour and sometimes none for days. Each file must be validated and its contents written to a database within a few minutes. The company wants no servers to manage and to pay nothing when no files arrive. Which Azure compute approach fits best?

The work is event-driven (a file arriving), short-running and highly variable, and the requirements exclude server management and idle costs. An Azure Functions app with a Blob Storage trigger on a consumption-based plan meets all of them: it runs when a file arrives, scales with the number of files and costs nothing while idle. A virtual machine would need management and would cost money while waiting for files. Logic Apps could also orchestrate the process, but validation logic written as code points to Azure Functions.

Check yourself

What starts each execution of a serverless function?

Show answer

A trigger, such as an HTTP request, a timer, a queue message or a new blob. Serverless is event-driven.

Exam Tips

Remember for the exam

  • Serverless: no server management, automatic scaling and billing per execution.
  • Serverless is event-driven; a trigger starts each execution.
  • Azure Functions is code-first; Azure Logic Apps is a designer-first workflow service.