AZ-900Chapter 18 of 127Objective 2.2

Azure Functions (Serverless)

This chapter covers Azure Functions, Microsoft's serverless compute service that lets you run event-driven code without managing servers. For the AZ-900 exam, understanding serverless concepts is crucial because they represent a core pillar of modern cloud architecture, and you can expect questions about use cases, pricing models, and how Azure Functions differs from other compute options. This objective area (Describe Azure architecture and services) typically accounts for 15-20% of the exam, with serverless being a frequently tested subtopic. By the end of this chapter, you will confidently answer any AZ-900 question about Azure Functions, including when to use it, its key features, and its role in a cloud solution.

25 min read
Beginner
Updated May 31, 2026

Azure Functions as a Pop-up Restaurant

Imagine you run a busy downtown business district. Instead of building a full-scale restaurant that operates 24/7 with a permanent kitchen, staff, and dining room (like a traditional server), you set up a 'pop-up restaurant' that only appears when customers order food. Each time a customer places an order (an event like an HTTP request or a new file in cloud storage), a small, temporary kitchen is assembled, the meal is cooked (your code runs), and the kitchen is dismantled immediately after the meal is served. You pay only for the cooking time and ingredients used, not for idle staff or empty dining space. Azure Functions works the same way: it runs your code in response to events, automatically scales to handle thousands of simultaneous orders, and charges only for the compute resources consumed during execution. Unlike a traditional server that sits idle most of the time, a pop-up kitchen is perfectly efficient—no waste, no overhead. If no orders come in, no kitchen exists, and you pay nothing. This is the essence of serverless computing: you focus on the recipe (your code), and Azure handles the logistics of kitchens, staff, and cleanup.

How It Actually Works

What Is Azure Functions and What Business Problem Does It Solve?

Azure Functions is a serverless compute service that allows you to run small pieces of code (called 'functions') in response to events, without provisioning or managing infrastructure. The fundamental business problem it solves is the inefficiency and complexity of running dedicated servers for code that only executes occasionally. In traditional on-premises or even IaaS environments, you must maintain a server (virtual or physical) that is always on, consuming resources and incurring costs even when no code is running. For workloads like processing uploaded images, responding to database changes, or handling webhook calls, this leads to significant waste.

Azure Functions eliminates this waste by abstracting away the server entirely. You upload your code, define what triggers it (e.g., an HTTP request, a new blob in Azure Storage, a message in a queue), and Azure automatically runs the code when the trigger fires. The service handles scaling, patching, and resource allocation. You pay only for the time your code executes and the resources it consumes (measured in gigabyte-seconds). This is ideal for unpredictable workloads, microservices, and automation tasks.

How Azure Functions Works – Step by Step

At its core, Azure Functions relies on a trigger and a binding. A trigger is what causes the function to run. Common triggers include: - HTTPTrigger: Fires when an HTTP request is received (e.g., from a web app or REST API call). - BlobTrigger: Fires when a new blob is created or updated in an Azure Storage container. - QueueTrigger: Fires when a message arrives in an Azure Storage Queue. - TimerTrigger: Fires on a schedule (like a cron job). - EventGridTrigger: Fires when an Azure Event Grid event occurs. - CosmosDBTrigger: Fires when a document changes in a Cosmos DB collection.

Bindings are a declarative way to connect your function to other Azure services without writing connection code. There are input bindings (read data from a service) and output bindings (write data to a service). For example, a function triggered by an HTTP request might use an input binding to read a document from Cosmos DB and an output binding to write a message to a queue.

When a trigger event occurs, Azure Functions runtime (running on the Azure App Service platform) allocates a sandboxed execution environment, runs your code, and then tears it down after execution (or keeps it warm for a few minutes if you use the Premium plan). The runtime automatically scales out by creating more instances of your function app as the event rate increases.

Key Components, Tiers, and Pricing Models

Azure Functions has two main hosting plans relevant to AZ-900:

Consumption Plan: This is the true serverless plan. You are charged only for the time your code runs, rounded up to the nearest millisecond. The plan includes a generous free grant (1 million executions and 400,000 GB-s per month). It scales automatically from zero to thousands of instances based on demand. However, there is a timeout limit of 5 minutes for the function execution (can be increased to 10 minutes for the plan). Cold starts (when a function hasn't been invoked recently) can introduce latency.

Premium Plan: This plan offers better performance and features like always-ready instances (eliminating cold starts), unlimited execution duration (up to 60 minutes), and more powerful instances (more memory and CPU). You pay for the pre-warmed instances and any additional executions. This is suitable for enterprise workloads that need consistent performance.

Dedicated Plan (App Service Plan): You run functions on a regular App Service plan, which means the VM is always on. This is not serverless in the strict sense because you pay for the VM even when no code runs. It's used when you need to combine functions with other App Service resources or require predictable billing.

Key components of a function app include: - Function App: The container that holds one or more functions. It provides the execution context (runtime stack, environment variables, etc.). - Triggers and Bindings: Defined in the function.json file or via attributes in code. - Host Configuration: The host.json file configures runtime behavior (e.g., global timeout, concurrency limits).

How It Compares to On-Premises Equivalent

In an on-premises environment, to run code in response to an event (e.g., a file being dropped into a folder), you would: 1. Provision a server (physical or VM). 2. Install an operating system and any required runtime (e.g., .NET, Node.js). 3. Write a Windows Service or scheduled task that polls for the event. 4. Handle scaling manually by adding more servers. 5. Pay for electricity, cooling, maintenance, and staff.

With Azure Functions, you skip steps 1-4 entirely. You write the code, define the trigger, and deploy. Azure handles the rest. The cost model shifts from capital expenditure (CAPEX) to operational expenditure (OPEX) with pay-per-use billing.

Azure Portal and CLI Touchpoints

To create a Function App in the Azure portal: 1. Navigate to 'Create a resource' > 'Compute' > 'Function App'. 2. Provide a name, subscription, resource group, and runtime stack (e.g., .NET, Node.js, Python). 3. Choose the hosting plan (Consumption, Premium, or Dedicated). 4. Configure storage account (required for triggers and logs). 5. Review and create.

Using Azure CLI:

az functionapp create --resource-group myResourceGroup --consumption-plan-location westus --runtime dotnet --functions-version 4 --name myFunctionApp --storage-account mystorageaccount

This creates a function app on the Consumption plan. You can then deploy code using func azure functionapp publish or through continuous deployment.

Concrete Business Scenarios

Image Processing: An e-commerce site uploads product images to Azure Blob Storage. A Blob-triggered function automatically resizes the image and creates a thumbnail, then stores it in a different container. The function runs only when a new image is uploaded, scaling to handle thousands of uploads during a sale.

Webhook Handling: A SaaS application sends webhook events (e.g., new customer signup) to an HTTP-triggered function. The function validates the payload, writes to a database, and sends a welcome email via SendGrid. This avoids the need for a constantly running web server.

Scheduled Data Cleanup: A Timer-triggered function runs every night at 2 AM to delete old records from a database that are older than 90 days. This is a simple, cost-effective replacement for a scheduled task on a VM.

Common Misconfigurations

Not setting the correct timeout: In Consumption plan, the default timeout is 5 minutes. Long-running tasks will fail silently. Either switch to Premium plan or refactor the code.

Ignoring cold starts: For latency-sensitive applications, using Consumption plan can cause delays. Always consider Premium plan with always-ready instances.

Overusing bindings: Complex binding expressions can slow down execution. Keep bindings simple and use SDKs for heavy data operations.

Walk-Through

1

Create a Function App

In the Azure portal, click 'Create a resource' and search for 'Function App'. Fill in the basics: subscription, resource group (create new or use existing), Function App name (must be globally unique), runtime stack (e.g., .NET 6, Node.js 18), and region. Choose the hosting plan – for serverless, select 'Consumption (Serverless)'. You must also create or select a storage account; this is required for the Functions runtime to manage triggers and execution logs. Click 'Review + create' and then 'Create'. Behind the scenes, Azure provisions the necessary infrastructure: a storage account for queue/table storage, a hosting environment, and the runtime. This typically takes 30-60 seconds.

2

Add a Trigger and Write Code

Inside your Function App, click 'Functions' then 'Create'. Select a trigger template – for example, 'HTTP trigger'. Set the authorization level (Function, Anonymous, or Admin). Click 'Create'. Azure generates a default code file (e.g., run.csx for C#) with the trigger logic. Replace the code with your own. For example, in C#, the function signature includes an HttpRequest parameter and an IActionResult return. The trigger metadata is stored in a function.json file that defines bindings. You can add input/output bindings by editing function.json or using attributes in compiled languages. Write your business logic – e.g., parse the request body, process data, return a response.

3

Test the Function Locally

Before deploying, test locally using Azure Functions Core Tools. Install the tools (npm install -g azure-functions-core-tools@4). In your project folder, run 'func start'. The tool emulates the Functions runtime and displays the local URL (e.g., http://localhost:7071/api/MyFunction). Use a tool like curl or Postman to send an HTTP request to that URL. Observe the logs in the console. Local testing catches syntax errors and logic issues before incurring cloud costs. The local emulator also supports other triggers like queues and blobs via Azurite, a local storage emulator. Once satisfied, you can deploy.

4

Deploy to Azure

Deploy your function code to the Function App using the Azure CLI or Visual Studio. For CLI, run 'func azure functionapp publish <FunctionAppName>' from your project directory. This command zips your code and uploads it to Azure, updating the function app. Behind the scenes, Azure compiles the code if needed (e.g., for C#), registers the function with the runtime, and makes it ready to receive events. You can also set up continuous deployment from GitHub or Azure DevOps, so every push automatically updates the function. After deployment, you can test the live function by using the URL provided in the portal (e.g., https://myfunctionapp.azurewebsites.net/api/MyFunction).

5

Monitor and Scale

Azure Functions integrates with Application Insights for monitoring. Enable it during creation or later. You can view execution counts, failure rates, and average duration. The 'Monitor' tab in the portal shows recent invocations and logs. For scaling, the Consumption plan automatically scales out based on the number of incoming events. The runtime monitors the trigger rate and adds more instances as needed, up to a default maximum of 200 instances per function app. Scaling is instantaneous for HTTP triggers but may have a slight delay for other triggers. You can configure scaling limits in the 'Scale out' settings (Premium plan only). Use Application Insights to set alerts for errors or high latency.

What This Looks Like on the Job

Scenario 1: Real-Time Order Processing for an E-Commerce Platform

A mid-sized e-commerce company processes thousands of orders daily. Each order triggers a series of actions: validate inventory, charge credit card, send confirmation email, and update the warehouse system. Traditionally, this was handled by a monolithic application running on a dedicated server, which was expensive and hard to scale during peak seasons like Black Friday. The team migrated to Azure Functions. An HTTP-triggered function receives the order from the web frontend. It validates the payload, then uses output bindings to write to a queue (Azure Queue Storage) for further processing. A separate Queue-triggered function picks up the message, processes payment via a third-party API, and writes results to a database. A third function sends the confirmation email via SendGrid. The system scales automatically: during low traffic, only a few instances run; during a flash sale, Azure spins up hundreds of instances to handle the load. Cost is a fraction of the old server bill because the company pays only for execution time. The team monitors everything with Application Insights and sets alerts for failed payments or slow responses. One common mistake: not setting a longer timeout (default 5 minutes) for payment processing that occasionally takes longer, causing silent failures. They switched to Premium plan for those critical functions.

Scenario 2: Automated Image Resizing for a Social Media App

A social media startup allows users to upload photos. The backend must create multiple thumbnail sizes (e.g., 150x150, 300x300) and store them in a CDN. Previously, they used a VM with a cron job that polled a folder every minute. This wasted resources and introduced latency. They replaced it with a Blob-triggered Azure Function. When a user uploads a photo to Azure Blob Storage (via the app), the Function is triggered. It reads the image, uses a library (e.g., ImageSharp) to resize, and writes the thumbnails back to a different container. The function runs only when a photo is uploaded, scaling to thousands of concurrent uploads. Cost is minimal – the free grant covers millions of executions. However, they hit a cold start issue: the first upload after a period of inactivity took several seconds. They enabled 'Always Ready' instances in the Premium plan for the thumbnail function to keep it warm. Another pitfall: they originally used the Consumption plan with a 5-minute timeout, but some large images took longer to process. They refactored to process images in chunks or increased the timeout to 10 minutes (max for Consumption). The result: 50% cost reduction and faster time-to-market.

Scenario 3: Scheduled Database Cleanup for a SaaS Provider

A SaaS company stores user activity logs in Azure SQL Database. By policy, logs older than 90 days must be deleted to comply with data retention regulations. They used a scheduled task on a VM, but the VM had to run 24/7, costing $50/month. They replaced it with a Timer-triggered Azure Function that runs daily at 2 AM. The function connects to the database via a connection string stored in Application Settings, runs a DELETE query, and logs the number of deleted rows. The function runs for about 30 seconds each day. Monthly cost: a few cents. The team also added a second function that runs weekly to archive older logs to cold storage (Azure Archive Storage). This is a classic example of using serverless for simple automation tasks. A common mistake: not handling time zone differences – the timer trigger uses UTC, so they had to adjust the schedule accordingly. Also, they initially forgot to set the function to be retried on failure, so if the database was unreachable, the cleanup was missed. They added a retry policy in the function code.

How AZ-900 Actually Tests This

What AZ-900 Tests on This Objective (Objective 2.2)

AZ-900 objective 2.2 is titled 'Describe Azure compute and networking services'. Under compute, serverless is a key subtopic. The exam expects you to:

Identify the characteristics of serverless computing: no infrastructure management, automatic scaling, pay-per-execution.

Recognize Azure Functions as the primary serverless compute service.

Know the common triggers: HTTP, Timer, Blob, Queue, Event Grid.

Understand the pricing model: Consumption plan charges per execution and per gigabyte-second; Premium plan charges for pre-warmed instances.

Differentiate between Azure Functions and other compute options like Azure App Service, Azure Logic Apps, and Azure Container Instances.

Identify appropriate use cases: event-driven processing, data transformation, API endpoints, scheduled tasks.

Common Wrong Answers and Why Candidates Choose Them

1.

'Azure Functions requires a virtual machine to run.' – This is false. The whole point of serverless is that you don't manage VMs. However, candidates who think 'serverless' means 'still runs on servers but Microsoft manages them' sometimes overcorrect and think some VM must exist. In reality, the Consumption plan uses a shared multi-tenant environment; you never see a VM.

2.

'Azure Functions is the same as Azure Logic Apps.' – Both can be triggered by events, but Logic Apps are for workflows with connectors (no-code/low-code), whereas Functions are for custom code. The exam loves to ask which one to use for custom logic vs. integration workflows.

3.

'Azure Functions runs continuously like a web app.' – No, it runs only when triggered. Candidates confuse it with App Service. The key distinction is event-driven vs. always-on.

4.

'Azure Functions can only be written in C#.' – False. It supports many languages: C#, Java, JavaScript, Python, PowerShell, TypeScript, and more.

Specific Terms and Values That Appear on the Exam

Consumption Plan: Pay only for execution time; free grant: 1 million executions/month.

Premium Plan: Always-ready instances; no execution timeout limit (actually up to 60 minutes).

Cold start: Delay when a function hasn't been invoked recently; Premium plan reduces this.

Triggers: HTTP, Timer, Blob, Queue, Event Grid, Cosmos DB.

Bindings: Input and output connections to services.

Function App: The container that hosts one or more functions.

Timeout: Consumption plan default 5 minutes (max 10); Premium plan max 60 minutes.

Edge Cases and Tricky Distinctions

Azure Functions vs. Azure Logic Apps: Functions are for code; Logic Apps are for workflows with 200+ connectors. If the question says 'write custom code', choose Functions. If it says 'integrate SaaS applications without writing code', choose Logic Apps.

Azure Functions vs. Azure App Service WebJobs: WebJobs also run background tasks but require an App Service plan (always-on). Functions can be serverless. The exam may ask which is serverless – answer: Functions.

Durable Functions: An extension for stateful workflows. Not heavily tested on AZ-900, but you should know it exists for orchestrating multiple functions.

Scaling limits: Consumption plan scales to 200 instances; Premium plan can scale to 100 instances by default (configurable higher).

Memory Trick: 'FACTOR' for Functions

Functions are Fast, Automatic scaling, Cost-effective (pay per use), Trigger-driven, Only code (no infra), Run in many languages.

Decision tree for exam questions: 1. Is the task event-driven and requires custom code? -> Azure Functions. 2. Does it need to run on a schedule? -> Timer trigger in Functions (or Logic Apps). 3. Is it a long-running workflow with state? -> Durable Functions. 4. Is it a simple integration between SaaS apps without code? -> Logic Apps. 5. Does it need to run continuously like a web server? -> App Service, not Functions.

Key Takeaways

Azure Functions is a serverless compute service that runs code in response to events, without managing servers.

Common triggers: HTTP, Timer, Blob, Queue, Event Grid, Cosmos DB.

Consumption plan: pay only for execution time; includes 1 million free executions per month.

Premium plan: eliminates cold starts with always-ready instances; max timeout 60 minutes.

Dedicated plan: runs on an App Service plan; not truly serverless.

Azure Functions supports multiple languages: C#, Java, JavaScript, Python, PowerShell, TypeScript, and more.

Bindings provide declarative connections to other Azure services for input and output.

Cold start is the initial delay when a function hasn't been invoked recently; mitigated by Premium plan.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Azure Functions (Consumption Plan)

Event-driven, runs only when triggered

Pay only for execution time (per second)

Automatic scaling from zero to 200 instances

Maximum execution timeout: 5 minutes (default), 10 minutes (max)

No infrastructure management; fully serverless

Azure App Service (Web App)

Always-on, continuously running web server

Pay for the VM instance (per hour or reserved)

Manual or auto-scale based on metrics

No execution timeout (runs indefinitely)

You manage the App Service plan (VM size, scaling)

Azure Functions

Runs custom code (C#, Python, JavaScript, etc.)

Requires developer skills to write code

Supports any trigger via code (HTTP, Timer, etc.)

Charged per execution and GB-s (Consumption plan)

Better for complex business logic and algorithms

Azure Logic Apps

Uses pre-built connectors (no code required)

Designed for non-developers and integration

Triggers and actions are configured visually

Charged per action execution (different pricing model)

Better for workflows integrating SaaS applications

Watch Out for These

Mistake

Azure Functions requires a virtual machine to run.

Correct

Azure Functions in the Consumption plan runs in a multi-tenant serverless environment without any visible VM. Microsoft manages the underlying servers. You never provision or manage a VM. The Premium plan also abstracts VMs, though it uses dedicated instances. Only the Dedicated plan (App Service plan) runs on a VM you manage.

Mistake

Azure Functions can only be triggered by HTTP requests.

Correct

Azure Functions supports many triggers: HTTP, Timer, Blob (Azure Storage), Queue (Azure Storage), Event Grid, Cosmos DB, Service Bus, Event Hubs, and more. HTTP is just one common trigger. The exam tests your knowledge of multiple triggers.

Mistake

Azure Functions is free for unlimited executions.

Correct

The Consumption plan includes a free grant of 1 million executions and 400,000 GB-s per month, but beyond that you pay per execution and per gigabyte-second. Premium and Dedicated plans have different pricing. There is no unlimited free tier.

Mistake

Azure Functions runs continuously like a web app.

Correct

Azure Functions is event-driven and runs only when triggered. It does not run continuously. After execution, the instance may be kept warm for a few minutes (Consumption plan) or stay ready (Premium plan), but it does not process requests without triggers. This is a key difference from Azure App Service.

Mistake

Azure Functions is the same as Azure Logic Apps.

Correct

Both are serverless, but Azure Functions runs custom code (e.g., C#, Python) while Azure Logic Apps provides pre-built connectors for workflows without code. Functions are for developers; Logic Apps are for integrators. The exam often asks which to use for a given scenario.

Frequently Asked Questions

What is the difference between Azure Functions and Azure Logic Apps?

Azure Functions is for running custom code (e.g., C#, Python) in response to events. Azure Logic Apps is a low-code/no-code workflow service that integrates SaaS applications using pre-built connectors. Use Functions when you need to write custom logic; use Logic Apps when you need to connect services without code. For AZ-900, remember: Functions = code, Logic Apps = connectors.

Does Azure Functions support long-running tasks?

The Consumption plan has a maximum execution timeout of 5 minutes (configurable up to 10 minutes). For longer tasks, use the Premium plan (up to 60 minutes) or the Dedicated plan (no timeout). Alternatively, you can use Durable Functions to orchestrate long-running workflows by chaining multiple short-lived functions.

What is a cold start in Azure Functions?

A cold start occurs when a function hasn't been invoked for a while and the runtime needs to load your code and dependencies from scratch. This adds latency (typically 1-10 seconds). The Consumption plan experiences cold starts after periods of inactivity. The Premium plan eliminates cold starts by keeping instances always ready. For latency-sensitive applications, use the Premium plan.

Can Azure Functions be used for API endpoints?

Yes, an HTTP-triggered function can serve as a REST API endpoint. It can accept GET, POST, PUT, DELETE requests and return JSON responses. You can secure it with authentication (Function keys, Azure AD, etc.). This is a common pattern for microservices. However, for full web applications with static content, Azure App Service is more appropriate.

How does Azure Functions scale?

The Consumption plan automatically scales based on the number of incoming events. For HTTP triggers, scaling is near-instantaneous. For other triggers, there may be a slight delay. The default maximum number of instances is 200 per function app. The Premium plan allows you to set a minimum number of always-ready instances and scale up to 100 instances (configurable higher).

What is the pricing model for Azure Functions?

The Consumption plan charges per execution ($0.20 per million executions) and per gigabyte-second ($0.000016/GB-s). There is a free grant of 1 million executions and 400,000 GB-s per month. The Premium plan charges for the pre-warmed instances (based on vCPU and memory) plus additional execution costs. The Dedicated plan charges for the App Service plan VM.

What are bindings in Azure Functions?

Bindings are a declarative way to connect your function to other Azure services without writing connection code. Input bindings read data from a service (e.g., a blob from storage) before the function runs. Output bindings write data to a service (e.g., a queue message) after the function runs. Bindings reduce boilerplate code and make functions easier to maintain.

Terms Worth Knowing

Ready to put this to the test?

You've just covered Azure Functions (Serverless) — now see how well it sticks with free AZ-900 practice questions. Full explanations included, no account needed.

Done with this chapter?