Azure Functions
Azure Functions is a serverless compute service that runs your code on-demand, billing only for execution time — no servers to manage, no idle costs.
Simple Explanation
A light-switch: you wire it up, and it turns on only when something flips it. Functions execute in response to events, then stop — you pay only for the milliseconds they run.
When to Use Functions
- Event-driven tasks: process a blob upload, respond to a queue message, fire on a timer.
- Lightweight HTTP APIs where per-request pricing is cheaper than running a server 24/7.
- Automation scripts (nightly cleanup, report generation).
- Glue code that connects services without building a full microservice.
Triggers
| Trigger | When it fires | Common usage |
|---|---|---|
| HTTP | Incoming web request | Lightweight APIs, webhooks |
| Timer | CRON schedule | Nightly jobs, cleanup |
| Blob Storage | File created/modified | Image resizing, ETL |
| Queue Storage | New queue message | Background processing |
| Service Bus | Message or topic | Enterprise messaging |
| Event Hub | Streaming event | IoT, telemetry |
| Cosmos DB | Document change feed | Replication, sync |
Hosting Plans
| Plan | Billed On | Cold Start? | Max Timeout |
|---|---|---|---|
| Consumption | Executions + GB-s | Yes (~1-3s) | 10 min |
| Premium | Pre-warmed instances | No | Unlimited |
| App Service | Plan tier | No | Unlimited |
On Consumption plan, if a function hasn't run recently, Azure must provision a new container — adding 1-3 seconds latency. Use Premium plan for user-facing APIs that can't tolerate cold starts.
Visual Representation
Commands
# Install Functions Core Tools (local dev) npm install -g azure-functions-core-tools@4 # Initialize a new function project func init my-func-app --worker-runtime node # Create a new HTTP-triggered function cd my-func-app func new --name HelloWorld --template "HTTP trigger" # Run locally func start # Create storage account (Functions require one) az storage account create \ --name stfuncstorage2024 \ --resource-group rg-functions \ --sku Standard_LRS # Create a Function App (Consumption plan) az functionapp create \ --resource-group rg-functions \ --consumption-plan-location eastus \ --runtime node \ --runtime-version 18 \ --functions-version 4 \ --name fn-app-myproject \ --storage-account stfuncstorage2024 # Deploy code func azure functionapp publish fn-app-myproject # View logs az webapp log tail --name fn-app-myproject --resource-group rg-functions
Hands-on
- Install Core Tools and create a local HTTP function in Node.js or Python.
- Run locally with
func startand test viacurl http://localhost:7071/api/HelloWorld. - Create a Function App on Consumption plan and deploy.
- Add a Timer trigger function with CRON expression
0 */5 * * * *(every 5 min). - View execution logs in the Portal under Monitor.
Debugging Scenario
Issue: HTTP function returns errors only under load.
- Consumption plan may be cold-starting under sudden traffic spikes.
- Check Application Insights for dependency timeouts (database connection pool exhausted).
- Functions on Consumption share infrastructure — move to Premium for consistent performance.
- Enable Application Insights and track function execution times per invocation.
Interview Questions
Beginner
A model where the cloud provider manages all server infrastructure. You deploy code, pay per execution, and the platform scales automatically — no idle compute costs.
The event that causes a function to run — HTTP request, timer schedule, queue message, blob upload, etc. Each function has exactly one trigger.
Intermediate
When you need no cold starts (user-facing APIs), longer timeout (> 10 min), VNet integration, or higher performance with predictable costs.
Scenario-based
Use a Blob Storage triggered Function. The trigger fires on new blob creation, the function reads the blob as input binding, processes it, and writes the resized version as output binding.
Summary
Azure Functions is ideal for event-driven, short-lived workloads. Consumption plan is cheapest for infrequent or variable workloads; Premium removes cold starts for production APIs. Always pair Functions with Application Insights for observability.