Azure Functions
Azure Functions runs small pieces of code in response to events — an HTTP request, a new file, a queue message, a timer — without managing servers.
On this page · 5 min · Intermediate
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Oct 29, 2026
Related tutorials
Learning objectives#
- Explain triggers and bindings
- Write an HTTP-triggered function
- Choose a hosting plan
- Know when serverless fits
Explanation#
A trigger starts a function: HTTP, Timer, Blob Storage, Queue Storage, Service Bus, Cosmos DB change feed and more. Bindings connect inputs and outputs declaratively.
Hosting plans: Flex Consumption (recommended serverless plan — scales to zero, pay per use, with optional always-ready instances), Premium (pre-warmed instances, VNet access) and Dedicated (runs on an App Service plan).
Scaling to zero saves money but can cause a cold start — a short delay when a new instance spins up.
Functions suit event-driven, short-running jobs. Long-running or constantly busy services are often cheaper on App Service or Container Apps.
Code example: HTTP function (Node.js v4 model)#
const { app } = require('@azure/functions');
app.http('hello', {
methods: ['GET'],
authLevel: 'anonymous',
handler: async (request, context) => {
const name = request.query.get('name') ?? 'world';
context.log(`Greeting ${name}`);
return { body: `Hello, ${name}!` };
},
});
// Run locally: func start
// Deploy: func azure functionapp publish <function-app-name>
GET http://localhost:7071/api/hello?name=Asha Hello, Asha!
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- app.http registers an HTTP-triggered function named hello.
- The handler reads a query-string parameter with a default.
- context.log writes to the function logs (and Application Insights).
- Returning { body } sends the HTTP response; the Functions host maps the route /api/hello.
Real-world use case#
Resize images when they are uploaded to Blob Storage, send a daily report on a timer, or process orders from a queue.
Common mistakes#
HTTP requests have time limits. Return quickly and hand off long work to a queue or Durable Functions.
Use always-ready instances or the Premium plan when latency matters.
Best practices#
- Keep functions small and stateless
- Use managed identity for connections
- Use queues for retries and spikes
- Monitor with Application Insights
Remember this#
Trigger = what starts it. Binding = what it reads/writes.
Serverless = scale to zero, pay per run.
Short and event-driven → Functions. Always busy → App Service or containers.
Practice exercise#
Your task: Change the function so it returns JSON: { message: "Hello, Asha!" }.
Show solution
return { jsonBody: { message: `Hello, ${name}!` } };
Mini quiz#
What starts an Azure Function?
Want more? Practise all Microsoft Azure MCQs · Microsoft Azure interview questions
My notes#
Saved in this browser.