Azure Function Pricing: How It Works and When to Use
Consumption Plan, where you pay for the number of executions, execution time, and memory used. There is also a Premium Plan with fixed pricing for reserved resources and advanced features. This pay-as-you-go model helps you save costs by only paying for what you use.How It Works
Think of Azure Functions like a pay-per-use electricity meter for your code. You only pay when your function runs, based on how long it runs and how much memory it uses. This is called the Consumption Plan. It’s like paying for water only when you open the tap.
There is also a Premium Plan where you reserve some resources ahead of time, like renting a car instead of paying per mile. This plan offers more power, no cold starts, and advanced networking options.
Azure counts the number of times your function runs, how long each run takes, and the memory size used during execution to calculate your bill. This way, small or infrequent tasks cost very little, while heavy workloads pay more.
Example
This example shows how to calculate the cost for 1 million function executions running for 1 second each with 1.5 GB memory on the Consumption Plan.
const executions = 1000000; const executionTimeSeconds = 1; const memoryGB = 1.5; // Pricing rates (example values, actual rates may vary) const pricePerMillionExecutions = 0.20; // $0.20 per million executions const pricePerGBSecond = 0.000016; // $0.000016 per GB-second const executionCost = (executions / 1000000) * pricePerMillionExecutions; const memoryCost = executions * executionTimeSeconds * memoryGB * pricePerGBSecond; const totalCost = executionCost + memoryCost; console.log(`Total cost: $${totalCost.toFixed(4)}`);
When to Use
Use Azure Functions when you want to run small pieces of code without managing servers. It’s great for tasks that happen occasionally or in response to events, like processing uploads, sending notifications, or running scheduled jobs.
The Consumption Plan is perfect if your workload is unpredictable or low volume because you only pay for what you use. The Premium Plan fits better when you need consistent performance, no delays on startup, or advanced network features.
Real-world examples include image resizing on upload, real-time data processing, or backend APIs for mobile apps.
Key Points
- Azure Functions pricing is mostly pay-per-use based on executions, duration, and memory.
- The Consumption Plan charges you only when your code runs, saving costs for low usage.
- The Premium Plan offers reserved resources and better performance for steady workloads.
- Costs depend on how many times your function runs and how long it runs with allocated memory.
- Ideal for event-driven, small, or bursty workloads without managing servers.