Serverless Isn't Always Cheaper: AWS Lambda vs. Azure Functions Architecture, Pricing and Hidden Costs
Understand function execution, scaling, warm capacity and dependency costs in AWS Lambda and Azure Functions, with workload calculations and operational tradeoffs.
A function can execute for a few dollars while its workload costs hundreds. API handling, database calls, NAT processing, storage, messaging and logs remain chargeable even when the compute line looks almost free.
Serverless changes the unit you buy and the work the provider operates. It does not remove the architecture. To judge whether it is cheaper, compare a complete workload with the same throughput, latency, availability and security requirements.
Calculations use illustrative USD rates, exclude free grants and discounts, and use a 730-hour month where relevant. They demonstrate mechanics rather than quote a selected region. This article focuses on Lambda’s default execution model and Azure Functions hosting plans; Lambda Managed Instances has a separate EC2-based cost model.
1. How functions execute and scale
A trigger delivers work to a function. The platform initializes an execution environment when needed, runs the handler, and may reuse the environment. Code should not depend on that reuse or on local state surviving indefinitely.
AWS Lambda’s default execution model scales execution environments as concurrency grows. Azure Functions scales according to its hosting plan, trigger and concurrency configuration. An Azure instance can handle concurrent executions, so invocation duration multiplied by invocation count is not a universal formula for every Azure plan’s bill.
Concurrency describes simultaneous work. At 200 requests/second and an average 0.25-second execution, average in-flight concurrency is about 50. Bursts and tail latency can require more capacity. Event-source limits, regional quotas, downstream connections and scaling speed can all constrain the system before its theoretical compute capacity.
2. The billing models are not identical
| Model | Main charging basis | Idle-capacity consideration |
|---|---|---|
| Lambda default on-demand | Requests and allocated memory × billed duration | No configured warm-capacity floor by default |
| Lambda provisioned concurrency | Configured warm capacity plus execution and requests | Warm capacity is charged while enabled |
| Functions Consumption | Executions and measured resource consumption under plan rules | Event-driven model; verify supported OS and features |
| Functions Flex Consumption | Executions, instance memory and active duration; optional Always Ready | Always Ready introduces baseline and execution meters |
| Functions Premium | Allocated cores and memory across required instances | At least one instance remains warm |
| Functions Dedicated | App Service plan capacity | Plan charges continue independently of invocation count |
Use Lambda pricing, Functions hosting options, and Functions pricing to select the actual model.
Lambda reserved concurrency limits and reserves concurrency allocation; it does not preinitialize environments or create a provisioned-concurrency charge. Provisioned concurrency keeps capacity initialized and has its own bill. Neither is a Reserved Instance purchase.
Lambda Managed Instances combines requests, EC2 capacity and management fees rather than default per-invocation duration billing. Do not apply the following GB-second example to it.
3. Requests, duration and memory: a worked example
Suppose a default Lambda-style workload executes two million times at an average billed duration of 0.2 seconds with 1 GB allocated memory. Assume $0.20 per million requests and $0.000016667 per GB-second.
Billed memory-duration = 2,000,000 × 0.2 × 1 = 400,000 GB-s
Duration cost = 400,000 × $0.000016667 = $6.6668
Request cost = 2 × $0.20 = $0.40
Function subtotal ≈ $7.07
This assumes billable requests and duration after applying the chosen metering rules, with grants deliberately excluded. Initialization, extensions, additional ephemeral storage, response streaming, event pollers and other features may have relevant charges. Handler stopwatch time alone may not capture every billed component.
For Flex Consumption, use billed instance-active memory-duration and its request meter. Concurrent calls sharing an instance mean you should use the plan’s observed billing quantities, not blindly add all overlapping invocation durations.
More memory can reduce or increase the bill
A 1 GB execution taking 100 ms consumes 0.10 GB-s. If 2 GB finishes in 40 ms, it consumes 0.08 GB-s: 20% less memory-duration. If it finishes in 60 ms, it consumes 0.12 GB-s: 20% more.
Benchmark realistic inputs and p95 latency. Additional memory can provide more CPU in Lambda, but I/O waits and downstream limits may prevent proportional speedup. The smallest memory setting is not automatically cheapest per completed operation.
4. Cold starts and the cost of being ready
Cold starts add initialization latency. Runtime, package size, imports, initialization logic, networking and dependencies all affect the observed result. Warm capacity can help meet latency requirements but creates an availability cost.
For a hypothetical warm-capacity meter, 20 environments × 1 GB × 730 hours × 3,600 seconds/hour at $0.000004/GB-s costs $210.24/month, before execution and request charges. This is an illustrative floor, not a current Lambda or Functions SKU quote.
On Azure, Flex Always Ready and Premium are different purchasing mechanisms; do not assume identical idle, active or minimum-instance billing. Scale-to-zero savings must also be weighed against startup latency and queue deadlines.
Schedule warm capacity where appropriate and supported, but assess traffic outside the schedule and failover behavior. A short monthly invocation report cannot show whether a latency-critical floor is justified.
5. Triggering services and dependency charges
API Gateway, EventBridge, SQS and streaming event sources have their own AWS economics. Azure API Management, Event Grid and Service Bus similarly remain separate products. A function triggered once can publish multiple messages and create several downstream operations.
Expand the $7.07 execution example using hypothetical observed monthly amounts:
| Workload component | Cost |
|---|---|
| Function requests and execution | $7.07 |
| API entry service | $7.00 |
| Logs and monitoring | $15.00 |
| State and object storage | $3.00 |
| Database operations/capacity | $90.00 |
| Networking and processing | $20.00 |
| Total workload | $142.07 |
These supporting amounts are assumptions, not provider tariffs. They show why reducing function duration by 20% cannot reduce the complete bill by 20%. The database is the largest contributor in this example.
Durable or multi-step workflows can add orchestration state, retries, storage transactions and repeated executions. Review execution history and billable operations instead of treating a business request as exactly one invocation.
6. Private networking does not disappear
Attaching Lambda to a VPC does not itself provide internet access. A public subnet does not automatically give the function a public IP. Public destinations may require NAT or another supported egress path; private service endpoints have different costs and restrictions.
Azure VNet integration and private endpoints also solve different directions of connectivity. Verify the hosting plan’s network features, outbound route and DNS. A private inbound endpoint is not a universal outbound connection.
Large responses, model downloads, database queries and verbose telemetry can make networking significant. Use the NAT comparison and private-endpoint guide to estimate the path.
7. Retries, duplicates and failure economics
Trigger behavior matters. Synchronous callers can retry; asynchronous systems and queue consumers have their own delivery, timeout and retry policies. At-least-once processing requires idempotency where duplicate work would be harmful.
Suppose 100,000 logical events produce 120,000 execution attempts. At equal duration, execution volume is 20% higher than the business event count. If every attempt also writes logs and calls a paid API, the amplification reaches those services too.
Set retry policies according to failure type. A dead-letter queue or failure destination preserves work for investigation but adds storage, messaging and replay activity. Partial-batch handling can avoid reprocessing already successful records when supported.
Track successful outcomes, attempts, throttles, queue age, timeouts and dependency failures together. Limiting concurrency can protect a database while increasing queue time; lowering cost without meeting the processing deadline is not an equivalent result.
8. When functions, containers or VMs fit better
Functions are attractive for irregular, event-driven work with suitable execution limits and low useful duty cycle. Containers can be attractive for longer-running services, custom runtime needs and efficient concurrency. VMs can suit stable, highly utilized capacity or workloads requiring host control.
For a simplified sensitivity calculation, assume function execution costs $0.000003 per successful operation and a suitable container service has a $60 monthly compute floor. Compute-only equality occurs at 20 million operations/month. That is not an architecture decision until retries, dependencies, readiness capacity and operational work are included.
Run both models against actual traffic shape. An average request rate conceals the bursts that determine scaling and the quiet periods that determine idle waste.
9. From a tuned function to an accountable workload
A developer can reduce package size or adjust memory. Across an organization, teams still need to know who owns the API, queues, network path and database, whether a release increased attempts, and whether the savings survived demand growth.
CloudVectra cost visibility supports AWS/Azure service-cost and trend analysis. Cost Centers add ownership and shared-cost context, while anomaly detection helps prioritize changes for investigation.
Use function metrics and traces to establish the technical cause. Keep the workload’s full bill visible after optimization rather than closing the review when one function becomes cheaper.