Skip to content

Azure Functions

Overview

Azure Functions is a serverless compute service that lets you run small units of code (“functions”) on-demand, in response to events, without having to provision or manage servers.

You write the logic, Azure handles the infrastructure, scaling, and billing — you’re charged only for the time your code runs.

Key Concepts

  • Trigger: Defines how a function is invoked (HTTP request, timer, queue message, etc.)
  • Binding: Input/output connections to other Azure services (e.g., Blob Storage, Cosmos DB, Service Bus)
  • Function App: A container for one or more functions sharing config, deployment, and scaling rules

Advantages

  • Pay-per-use – You’re charged only for executions and duration (in the Consumption plan)
  • Auto-scaling – Instantly scales up/down based on demand
  • Event-driven – Ideal for reacting to things like file uploads, database changes, or HTTP calls
  • Rapid development – Write minimal code with bindings and triggers
  • Supports multiple languages – C#, JavaScript, Python, Java, PowerShell, etc.
  • Integrated with Azure – Easy access to other services like Storage, Event Grid, Service Bus, etc.

Drawbacks / Considerations

  • Cold start latency (especially on the Consumption plan) – First request after idle may take longer
  • Execution timeout limits – Up to 5 minutes (Consumption) or longer (Premium/Dedicated plans)
  • Stateless – Designed for short-lived, stateless operations
  • Complex logic hard to manage – Not ideal for large monolithic workflows
  • Vendor lock-in – Heavily integrated with Azure-specific patterns

Example: HTTP-Triggered Function (C#)

Create a simple Azure Function to return a greeting:

public static class HelloFunction
{
    [FunctionName("HelloFunction")]
    public static IActionResult Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = "hello/{name}")] HttpRequest req,
        string name,
        ILogger log)
    {
        log.LogInformation($"Saying hello to {name}");
        return new OkObjectResult($"Hello, {name}!");
    }
}

This can be triggered via:

GET https://your-function.azurewebsites.net/api/hello/Stuart

Common Use Cases

  • HTTP APIs – Lightweight, serverless APIs
  • Timers – Scheduled background jobs (e.g., cleanup, polling)
  • Data processing – Process files, DB changes, queues
  • Event-driven automation – React to Azure Storage events, webhooks, messages
  • IoT and real-time data ingestion

Trigger Types

  • HTTP Trigger – Exposed as web endpoints
  • Timer Trigger – Runs on CRON schedules
  • Queue/Service Bus Trigger – Fires when new messages arrive
  • Blob Trigger – Fires when blobs are added/modified
  • Event Grid/Event Hub Trigger – React to system or custom events

Binding Example (Blob Output)

A function that processes and stores an image:

[FunctionName("ResizeImage")]
public static void Run(
    [BlobTrigger("images/in/{name}")] Stream inputImage,
    [Blob("images/out/{name}", FileAccess.Write)] Stream outputImage,
    ILogger log)
{
    // Resize image logic...
}

Monitoring & DevOps

  • Integrated with Application Insights for telemetry
  • Supports GitHub Actions, Azure DevOps, and CLI for CI/CD
  • Use the Azure Portal, VS Code, or Visual Studio to develop and deploy

Conceptual Model

Think of Azure Functions as “code-as-a-reaction”:

  • You write a small piece of logic
  • Azure wakes up, runs it when an event occurs
  • No servers, no containers, just focused code triggered by something

Pricing Plans

  1. Consumption Plan (default) – Auto-scales, billed per execution
  2. Premium Plan – Always warm, supports VNET, higher performance
  3. Dedicated (App Service) Plan – Runs on your reserved infrastructure

Further Reading