Azure Functions Beginner

What is Azure Functions?

Azure Functions runs small pieces of your code when something happens: an HTTP request, a timer, a queue message or a new file. Azure starts, scales and stops the servers for you, so you write the code that reacts to the event and nothing else.

How a function runs
  1. StartEvent happensAn HTTP call, a timer tick, a queue message or a new blob.
  2. Step 2Trigger firesThe Functions host sees the event and picks an instance.
  3. Step 3Your code runsThe method gets the event data as a parameter.
  4. Step 4Bindings write outputOptional outputs, such as a queue message or a database row.
  5. EndScale in or outMore instances when events pile up, none when idle.

Azure watches the event source and runs your method once per event.

The idea: code that reacts to events

A normal web app runs all the time and waits for requests. A function runs only when its trigger fires. Azure watches the event source, starts your code, passes it the event, and can run many copies at once when lots of events arrive.

This is called serverless: there are still servers, but you do not manage them. On consumption-style plans you pay for the time your code runs, and nothing when it is idle.

What a function app contains

  • A function app is the unit you deploy: one project with one or more functions that share settings and scale together.
  • Each function is a C# method marked with [Function("Name")] and exactly one trigger attribute.
  • host.json holds settings for the whole app, such as retries and logging levels.
  • Application settings hold connection strings and other configuration, like environment variables.
  • A Storage account is required by the runtime to keep its own state, such as timer schedules and leases.

A complete function

This function runs for every HTTP GET to /api/hello and returns a greeting. The trigger attribute tells Azure when to run it.

C#
public class HelloFunction(ILogger<HelloFunction> logger)
{
    [Function("Hello")]
    public IActionResult Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req)
    {
        string name = req.Query["name"].FirstOrDefault() ?? "world";
        logger.LogInformation("Saying hello to {Name}", name);
        return new OkObjectResult($"Hello, {name}!");
    }
}

When Functions is a good fit

  • Background work started by events: resize an uploaded image, process an order message, send an email.
  • Scheduled jobs: nightly clean-ups, reports, data syncs.
  • Small APIs and webhooks with spiky traffic.
  • Not ideal for big always-busy APIs with many endpoints or for long-lived connections; an ASP.NET Core app on App Service or Container Apps is simpler there. Many systems use both.

Interview question

What is Azure Functions and when would you use it instead of an ASP.NET Core Web API?

Azure Functions is serverless, event-driven compute: code runs when a trigger fires (HTTP, timer, queue, blob) and Azure scales it, including to zero. I use it for background and spiky work such as processing messages, uploads and scheduled jobs. For a large, always-busy API with many endpoints and complex middleware I prefer an ASP.NET Core app, often calling functions for the background work.

Your progress is saved only in this browser.

Want the full details? Read the official Microsoft documentation for this topic.