AZURE / SERVERLESS

Serverless & Consumption-Based Services

Pay only for what you use—turn flat-fee services into variable costs that scale with demand

Why This Matters

Traditional cloud services like App Service and always-on virtual machines charge a flat monthly fee regardless of usage. If your application only handles traffic during business hours or has unpredictable spikes, you're paying for idle capacity.

Serverless and consumption-based services like Azure Functions and Container Apps flip this model—you pay per execution, per second of CPU time, or per request. When there's no traffic, you pay nothing (or near-nothing).

For CFOs, this is a dream: variable costs that directly correlate with business activity. When revenue drops, costs automatically drop. When demand spikes, you pay more but you're also earning more.

The Financial Shift

Model Pricing Cost When Idle Best For
Flat-Fee
(App Service Standard S1)
$73/month
regardless of usage
$73/month
(100% cost)
Constant traffic,
predictable load
Consumption
(Azure Functions)
$0.20 per million executions
+ $0.000016/GB-second
$0/month
(0% cost)
Intermittent traffic,
unpredictable spikes
Scale-to-Zero
(Container Apps)
$0.000024/vCPU-second
+ $0.0000025/GiB-second
$0/month
(0% cost)
Microservices,
event-driven apps

Illustrative Scenario: API Modernization

This is a hypothetical, illustrative example for teaching purposes, not an actual case study.

Your company runs an internal HR API used by web and mobile apps. It handles employee lookups, time-off requests, and expense submissions. Traffic is concentrated during business hours (8 AM - 6 PM weekdays), with minimal usage nights and weekends.

Current Architecture (Flat-Fee)

  • Service: Azure App Service Standard S1 (1 core, 1.75 GB RAM)
  • Availability: Running 24/7/365
  • Traffic Pattern: 5 million API calls/month (80% during business hours, 20% off-hours)
  • Cost: $73/month × 12 months = $876/year

Proposed Architecture (Consumption)

Option 1: Azure Functions (Consumption Plan)

  • Executions: 5 million/month
  • Avg execution time: 200ms at 512 MB memory
  • Compute cost: (5M × 0.2 sec × 0.5 GB) × $0.000016/GB-sec = $8.00/month
  • Execution cost: (5M - 1M free) × $0.20/million = $0.80/month
  • Total cost: $8.80/month × 12 months = $105.60/year

Option 2: Container Apps (Consumption)

  • vCPU: 0.5 vCPU running 220 hours/month (realistic business hours, ~8 AM–6 PM weekdays)
  • Memory: 1 GiB
  • Compute cost: (0.5 vCPU × 792,000 sec) × $0.000024 = $9.50/month
  • Memory cost: (1 GiB × 792,000 sec) × $0.0000025 = $1.98/month
  • Total cost: $11.48/month × 12 months = $137.81/year

Annual Savings Analysis

  • App Service (current): $876/year
  • Azure Functions: $105.60/year → $770 savings (88% reduction)
  • Container Apps: $137.81/year → $738 savings (84% reduction)

Winner: Azure Functions still saves the most for this workload ($770/year, 88% reduction), but with a realistic ~220 business-hours/month usage figure, Container Apps is now competitive too—$137.81/year, an 84% reduction versus App Service. Both consumption options are dramatically cheaper than the flat-fee App Service plan; Functions' per-execution billing has a slight edge for short-duration requests like this one, but Container Apps is a reasonable choice if you need container portability or plan to run other workloads on the same environment.

Important Consideration: When Consumption Costs More

If your API had constant high traffic (e.g., 50 million requests/month running near 24/7), Functions would cost ~$88/month ($1,056/year) while App Service Standard S1 stays at $876/year. At high utilization, flat-fee becomes cheaper.

Rule of thumb: Consumption pricing wins when idle time > 40% or when traffic is unpredictable. Flat-fee wins when running near-constantly at steady load.

Impact on Financial Statements

Let's scale this up: Your company has 12 similar APIs and background jobs running on App Service. Migrating 8 of them (the ones with intermittent traffic) to Azure Functions would save $6,160/year ($770 × 8).

Profit & Loss Impact

Real-world company: $12M annual revenue, 200 employees

Line Item Before Serverless After Serverless Change
Revenue $12,000,000 $12,000,000 —
Cost of Goods Sold $1,800,000 $1,800,000 —
Gross Profit $10,200,000 $10,200,000 —
Gross Margin % 85.0% 85.0% —
Operating Expenses
Salaries & Benefits $7,200,000 $7,200,000 —
Cloud Infrastructure $780,000 $773,840 -$6,160
Sales & Marketing $720,000 $720,000 —
General & Administrative $360,000 $360,000 —
Total Operating Expenses $9,060,000 $9,053,840 -$6,160
EBIT (Operating Income) $1,140,000 $1,146,160 +$6,160
Operating Margin % 9.5% 9.6% +0.1pp

Key insight: While $6,160 seems small for a $12M company, serverless also adds operational resilience—automatic scaling during traffic spikes means you don't need to over-provision capacity "just in case." CFOs love this because it eliminates waste from idle resources while maintaining flexibility.

When to Use Consumption Pricing

Perfect Use Cases

  • Event-driven workflows: Processing files dropped in blob storage, responding to queue messages
  • Scheduled jobs: Nightly ETL processes, weekly reports, monthly invoicing
  • APIs with intermittent traffic: Internal tools used during business hours, seasonal applications
  • Webhooks and integrations: Responding to external events (Stripe payments, GitHub commits)
  • Microservices with uneven load: Authentication service gets 100x more calls than admin service
  • Background processing: Image resizing, video transcoding, document generation
  • IoT data ingestion: Handling sporadic device telemetry
  • Dev/test environments: Only pay when developers are actively testing

Poor Use Cases

  • Long-running processes: If execution time > 5 minutes, per-second billing gets expensive
  • High-volume constant traffic: API serving 1000+ requests/sec 24/7 is cheaper on flat-fee compute
  • Stateful applications: Apps that maintain in-memory state or long-lived connections
  • Latency-sensitive user-facing apps: Cold starts (0.5-3 seconds) hurt user experience
  • Large memory/CPU requirements: If you need 8+ GB RAM or 4+ cores, dedicated compute is cheaper
  • Legacy monoliths: Applications not designed for stateless, event-driven architecture

Azure Consumption Services Comparison

Service Best For Pricing Model Cold Start
Azure Functions
(Consumption)
Event-driven code,
APIs, scheduled jobs
Per execution
+ GB-seconds
0.5-3 sec
(HTTP trigger)
Container Apps
(Consumption)
Microservices,
containerized workloads
Per vCPU-second
+ GiB-second
1-5 sec
(scale from zero)
Logic Apps
(Consumption)
Workflow automation,
integrations
Per action executed
+ connector calls
Minimal
(managed service)
API Management
(Consumption)
API gateway,
dev/test APIs
Per million calls Minimal
(managed service)
Azure SQL
(Serverless)
Dev/test databases,
intermittent workloads
Per vCore-second
+ storage
~3 sec
(auto-pause/resume)

Implementation Approach

Step-by-Step Migration

Phase 1: Identify Candidates (Week 1-2)

  1. Audit current App Services and VMs for utilization patterns
  2. Pull 30 days of metrics: CPU %, memory %, request count, request duration
  3. Calculate idle time percentage (hours with < 5% CPU)
  4. Flag workloads with > 40% idle time as consumption candidates
  5. Estimate consumption costs using Azure Pricing Calculator

Phase 2: Pilot Conversion (Week 3-4)

  1. Choose 1-2 low-risk workloads (internal APIs, scheduled jobs)
  2. Refactor code for statelessness and short execution times
  3. Deploy to Azure Functions or Container Apps
  4. Run in parallel with existing service for 2 weeks
  5. Compare actual costs vs projections

Phase 3: Scale Rollout (Month 2-3)

  1. Migrate remaining qualified workloads
  2. Implement monitoring for cold start latency and function execution times
  3. Set up cost alerts in Azure Cost Management
  4. Document cost savings for quarterly business review

Code Refactoring Checklist

  • Stateless design: No in-memory session state, use Redis/Cosmos DB for state
  • Short execution time: Target < 60 seconds per function
  • Idempotent operations: Handle retries gracefully (functions can be invoked multiple times)
  • Externalize configuration: Use Azure App Configuration or Key Vault, not hardcoded settings
  • Efficient cold start: Minimize dependencies, lazy-load heavy libraries
  • Connection pooling: Reuse database/HTTP connections across invocations

Monitoring & Cost Control

Consumption pricing is powerful but requires active monitoring. Without visibility, a runaway function can generate millions of executions and surprise you with a massive bill.

Essential Monitoring

  • Azure Monitor: Function execution count, duration, failure rate, cold start frequency
  • Application Insights: Distributed tracing, dependency tracking, performance analysis
  • Azure Cost Management: Daily spend by resource, budget alerts, cost anomaly detection
  • Turbo360: Cross-subscription cost tracking, consumption pattern analysis

Cost Runaway Risks

  • Infinite loops: Function that triggers itself repeatedly → millions of executions
  • Chatty APIs: Function making 100 external API calls per execution → high network egress costs
  • Excessive retries: Failed function retrying 1000 times → wasted compute
  • Large data transfers: Functions moving GBs per execution → data transfer charges
  • Premium tiers by accident: Enabling Durable Functions or Premium plan features without realizing cost impact

Mitigation: Set daily spending limits in Azure Cost Management and configure alerts at 50%, 80%, 100% of budget.

Common Pitfalls

Mistake: Assuming Serverless = Free

The problem: "Consumption plan has a free tier of 1 million executions, so our API is free!"

Reality: You still pay for compute time (GB-seconds). A "free" API with 1M requests at 500ms each and 512 MB memory = 250,000 GB-seconds × $0.000016 = $4.00. Not free, but very cheap.

Mistake: Ignoring Cold Start Impact

The problem: User-facing web app experiences 3-second delays on first request after idle period.

Fix: Either accept the trade-off (if cost savings justify it), use Premium Plan with pre-warmed instances (costs more but eliminates cold start), or keep a warmup timer trigger pinging the function every 5 minutes.

Mistake: Converting Everything to Serverless

The problem: "Serverless is cheaper, let's migrate our entire platform!"

Reality: High-traffic always-on services are more expensive on consumption pricing. A 24/7 API handling constant traffic should stay on App Service or dedicated compute.

Mistake: Not Optimizing Execution Time

The problem: Function takes 5 seconds to process when it could take 500ms with better code.

Impact: You're paying 10x more per execution. Optimize aggressively: reduce dependency loading, cache configuration, use connection pooling, parallelize I/O operations.

Azure Functions vs Container Apps: Which One?

Factor Azure Functions Container Apps
Best For Short-lived event-driven tasks Containerized microservices
Execution Model Per-function invocation Long-running HTTP/gRPC services
Cold Start 0.5-3 seconds 1-5 seconds
Max Timeout 10 minutes (consumption) Unlimited
Pricing Cheaper for short bursts Cheaper for sustained runtime
Language Support C#, JavaScript, Python, Java, PowerShell Any language (containerized)
Built-in Triggers HTTP, Timer, Queue, Blob, Event Hub, etc. HTTP, gRPC, KEDA-based (custom)
Complexity Simpler (managed runtime) More control (BYO container)

Rule of thumb:

For Cloud Engineers: Executive Summary

When presenting serverless migration to leadership, emphasize financial flexibility. This is your talking track:

"We can reduce infrastructure costs by migrating intermittent workloads to consumption-based pricing."

  • Opportunity: 8 of our 12 APIs have < 50% utilization—we're paying for idle capacity
  • Solution: Azure Functions or Container Apps with pay-per-use pricing
  • Impact: $6,160/year savings with zero reduction in capability
  • Risk mitigation: Run pilot for 2 weeks in parallel to validate performance
  • Business value: Costs now scale with demand—if business slows, spend drops automatically
  • Timeline: 6 weeks to migrate all qualified workloads

Key CFO benefit: "This converts fixed costs into variable costs that correlate with business activity. During slow periods or recessions, our infrastructure spend automatically decreases."

Ready for the Next Topic?

Continue your learning journey