Table of Contents
- How Do Serverless and Container Costs Compare?
- How Are Serverless and Container Prices Calculated?
- At What Point Are Containers Cheaper Than Serverless?
- When Is Serverless Cheaper Than Containers?
- When Are Containers Cheaper Than Serverless?
- What Are the Hidden Costs of Running Serverless?
- How Much Do Real Workloads Cost on Serverless vs Containers?
- How Do You Build a Hybrid Serverless and Container Architecture?
- FAQ
- Sources
TLDR: Serverless wins for low-traffic workloads under 10% duty cycle (Lambda costs $0.90/month for a 2-minute daily job vs $72/month for 24/7 container). Containers win above 50% duty cycle or 50,000 invocations per day (processing 50,000 images costs $4.80 on containers vs $380 on serverless, 79x cheaper). Hidden serverless costs include cold starts, NAT gateway fees ($33/month per AZ), and data transfer between functions ($0.01-0.09/GB). Hybrid approach saves 46% vs all-serverless and 26% vs all-container by mixing serverless for sporadic tasks with containers for always-on workloads.
A team I worked with migrated their API to Lambda to save money. Three months later, their bill was 3x higher than running containers. The problem? Their API handled 200,000 requests per day with predictable traffic. Serverless is cheaper in theory, expensive in practice for the wrong workload.
After 9+ years managing cloud infrastructure, I’ve seen serverless save 80-90% (AWS, 2026) for batch jobs and waste 300% for always-on APIs. The difference is understanding when pay-per-invocation beats pay-per-hour.
Serverless vs containers cost depends on traffic patterns and duty cycle. Serverless (Lambda, Cloud Functions, Azure Functions) charges per invocation and execution time, winning for sporadic workloads under 10% duty cycle or under 50,000 daily invocations. Containers (ECS, Fargate, Kubernetes) charge per hour regardless of usage, winning for consistent traffic above 50% duty cycle. Hidden serverless costs include cold starts, NAT gateway fees, and billing granularity. Most teams use both: serverless for event-driven tasks, containers for always-on services.
How Do Serverless and Container Costs Compare?
Serverless platforms charge per invocation plus execution time (AWS Lambda: $0.20 per 1M requests + $0.0000166667 per GB-second). Containers charge per hour of runtime (AWS Fargate: $0.04048 per vCPU-hour + $0.004445 per GB-hour). Serverless scales to zero when idle — 80-90% cheaper for sporadic workloads. Containers run 24/7 — 50-80% cheaper for always-on services.
The cost model difference is fundamental.
Serverless pricing (AWS Lambda pricing example):
- $0.20 per 1 million requests
- $0.0000166667 per GB-second of execution time
- 1 million seconds of free compute per month (400,000 GB-seconds at 128MB)
- Minimum billing: 100ms per invocation
- Scales to zero: $0 when not running
Container pricing (AWS Fargate pricing example):
- $0.04048 per vCPU-hour
- $0.004445 per GB-hour
- 1-minute minimum billing, then per-second
- No free tier
- Runs 24/7: $30-500/month minimum depending on size
(Pricing as of 2026. Verify current rates at AWS Lambda pricing and AWS Fargate pricing.)
Example cost for 1,000 invocations per day, 500ms average duration, 512MB memory:
| Platform | Monthly Invocations | Compute Time | Cost |
|---|---|---|---|
| Lambda | 30,000 | 250 minutes (4.2 hours) | $0.14 |
| Fargate (0.25 vCPU) | N/A | 720 hours (always-on) | $7.29 |
Serverless is 50x cheaper for this sporadic workload.
Example cost for 100,000 invocations per day, 200ms average duration, 1GB memory:
| Platform | Monthly Invocations | Compute Time | Cost |
|---|---|---|---|
| Lambda | 3,000,000 | 10,000 minutes (167 hours) | $15.60 |
| Fargate (0.5 vCPU) | N/A | 720 hours (always-on) | $14.58 |
Container is cheaper for this high-volume workload despite running 24/7.
How Are Serverless and Container Prices Calculated?
Serverless charges for requests plus execution time — AWS Lambda bills in 1ms increments, with a 1-million-request monthly free tier. Containers charge per vCPU-hour and GB-hour with a 1-minute minimum. Serverless scales to zero when idle, eliminating costs between invocations. Containers run 24/7 regardless of traffic. The billing model difference drives all cost comparison outcomes.
Understanding billing granularity matters for small invocations.
Lambda billing quirks:
Lambda changed from 100ms to 1ms billing granularity in December 2020. Short functions now cost exactly what they use — a 20ms invocation bills as 20ms. Google Cloud Functions Gen1 still bills in 100ms increments; Gen2 runs on Cloud Run which also rounds to 100ms. For sub-100ms functions, Lambda is now cheaper than GCF Gen1.
Real Lambda pricing calculation:
Function: 512MB memory, 150ms execution time, 1 million invocations/month
- Request cost: 1M requests × $0.20/1M = $0.20
- Compute cost: 1M invocations × 0.15 sec × 0.5GB = 75,000 GB-seconds
- Compute cost: 75,000 × $0.0000166667 = $1.25
- Total: $1.45/month
Fargate pricing calculation:
Task: 0.25 vCPU, 0.5GB memory, runs 24/7
- vCPU cost: 0.25 × 720 hours × $0.04048 = $7.29
- Memory cost: 0.5 × 720 hours × $0.004445 = $1.60
- Total: $8.89/month
For this example, Lambda is 6x cheaper because the workload only runs 2.5 hours total per month (150ms × 1M invocations / 3600 seconds = 41 hours equivalent, but Lambda only charges for actual execution).
Container cost consistency:
Containers cost the same whether they process 100 requests or 100,000 requests (assuming both fit within capacity). Serverless scales linearly with invocations.
At What Point Are Containers Cheaper Than Serverless?
The cost crossover between serverless and containers typically happens at 50,000 invocations per day or 10-50% duty cycle depending on execution time and memory requirements. Duty cycle (percentage of time actually executing vs idle) is a better metric than raw invocation count. Under 10% duty cycle, serverless almost always wins. Over 50% duty cycle, containers are usually cheaper.
Here’s the thing: the 50,000 invocation number comes from real-world analysis, not AWS marketing.

Duty cycle calculation:
Duty cycle = (Average execution time × Daily invocations × Memory) / (24 hours × Container memory)
Example:
- 10,000 invocations/day
- 500ms average execution time
- 512MB memory
Duty cycle = (0.5 sec × 10,000 × 0.5GB) / (86,400 sec × 0.5GB) = 5.8%
At 5.8% duty cycle, serverless wins. You’re paying for 5.8% utilization instead of 100%.
Crossover scenarios:
| Workload | Daily Invocations | Avg Duration | Duty Cycle | Winner | Monthly Cost Difference |
|---|---|---|---|---|---|
| Backup job | 1 | 2 minutes | <1% | Lambda | $0.90 vs $72 (80x) |
| Webhook handler | 5,000 | 100ms | 0.6% | Lambda | $0.40 vs $9 (22x) |
| Image processor | 50,000 | 2 seconds | 115% | Container | $15 vs $95 (6x) |
| API (steady traffic) | 200,000 | 50ms | 116% | Container | $10 vs $48 (5x) |
Note the image processor at 115% duty cycle (requires 1.15 containers worth of capacity). This is where containers clearly win.
When Is Serverless Cheaper Than Containers?
Serverless beats containers for sporadic workloads, event-driven processing, dev/test environments, scheduled tasks, and any workload idle more than 90% of the time. Perfect for S3 upload triggers, SNS/SQS processing, cron jobs, API endpoints with under 10 requests per minute, and batch jobs that run hourly or daily. Serverless saves 80-95% by scaling to zero between invocations.
Lambda’s superpower is not charging for idle time. In practice, 90% of scheduled jobs pay 10x more on containers than they need to.
Ideal serverless use cases:
Scheduled backups:
- Run daily at 3am for 2 minutes
- Duty cycle: 0.14% (2 min / 1440 min)
- Lambda: $0.90/month
- Container (t4g.small 24/7): $12/month
- Savings: 93%
S3 image resize on upload:
- 1,000 uploads per day
- 500ms processing time per image
- Lambda: $1.20/month
- Container: $9/month
- Savings: 87%
Webhook handler for GitHub events:
- 100 webhooks per day
- 50ms processing per webhook
- Lambda: $0.02/month (within free tier)
- Container: $9/month
- Savings: 99%
Dev environment APIs:
- Used 8 hours per weekday (40 hours/week)
- Idle 128 hours/week (76% idle)
- Lambda: Charged only for actual requests
- Container: $40/month for 24/7
- Savings: 60-80% (depends on dev usage patterns)
Unpredictable spikes:
Serverless handles traffic spikes without overprovisioning containers. Black Friday sale drives 50x normal traffic for 4 hours. Lambda scales automatically. Containers require manual scaling or overprovisioning 50x capacity all month (expensive).
I use Lambda for all scheduled jobs. A daily database backup that runs 3 minutes costs $0.60/month on Lambda. The equivalent always-on container would cost $15/month. Across 20 scheduled jobs, that’s $288/year saved.
When Are Containers Cheaper Than Serverless?
Containers beat serverless for always-on workloads, high-frequency processing, long-running tasks approaching 15-minute Lambda limits, data-intensive workloads transferring 5-20MB per invocation, and any workload with duty cycle above 50%. Perfect for production APIs, microservices, databases, real-time processing, web servers, and background job workers processing continuous queues. Containers save 50-80% for high-throughput workloads.
Containers cost the same whether processing 10 requests or 10,000 requests per hour.
Ideal container use cases:
Production REST API:
- 500 requests per second average
- 50ms per request
- Duty cycle: 2,500% (needs 25 containers worth of capacity)
- Lambda: $450/month
- Fargate: $220/month (10 tasks)
- Savings: 51%
Background job processor (Redis queue):
- Processes jobs continuously 24/7
- Average 100 jobs per minute
- 2 seconds per job
- Duty cycle: 200% (always busy, needs 2 workers)
- Lambda: $280/month
- Fargate (2 tasks): $35/month
- Savings: 87%
Image processing batch (50,000 images per day):
- 50,000 invocations
- 4 seconds per image
- Lambda: $380/month
- ECS on EC2 (t3.large spot): $4.80/month
- Savings: 99% (using spot instances)
Video transcoding:
- Long-running tasks (5-30 minutes per video)
- Approaching Lambda 15-minute timeout
- Data transfer (500MB input, 200MB output)
- Lambda: High cost due to data transfer + long duration
- Container: Fixed cost regardless of data size
- Savings: 70-90%
WebSocket server:
- Maintains persistent connections
- Serverless requires workarounds (API Gateway WebSocket + Lambda)
- Connection management overhead
- Container: Native WebSocket support
- Savings: 40-60%
A team migrated their queue processor from Lambda to Fargate and cut costs from $1,200/month to $180/month (85% savings). The queue had consistent 24/7 traffic, making containers a perfect fit.
Running containers on Kubernetes? The Kubernetes cost optimization guide covers 7 strategies to cut your K8s bill by 40-60%.
What Are the Hidden Costs of Running Serverless?
Hidden serverless costs include NAT gateway fees for VPC access ($33/month per AZ plus data transfer), provisioned concurrency to eliminate cold starts ($17-54/month per function), data transfer between functions ($0.01-0.09/GB), and CloudWatch Logs storage ($0.50/GB). These hidden costs double or triple expected bills. NAT gateways alone can exceed Lambda compute costs for low-volume, VPC-based workloads.
Serverless marketing focuses on compute costs and ignores infrastructure overhead.
NAT gateway costs:
Lambda in VPC requires NAT gateway for internet access (security best practice).
- $0.045/hour per NAT gateway = $32.85/month
- $0.045/GB data processed
- $0.09/GB data transfer = $0.135/GB total
For high availability, you need one NAT gateway per AZ (3 AZs = $98.55/month base cost). This is the minimum cost before any Lambda invocations run.
Example: Lambda processes 100GB data/month through NAT gateway:
- 3 NAT gateways: $98.55/month
- Data processing: 100GB × $0.135 = $13.50/month
- Total NAT cost: $112.05/month
Now add Lambda compute costs on top of that. For low-volume workloads, NAT gateway costs can exceed Lambda execution costs.
Provisioned concurrency costs:
Cold starts average 200-500ms for Lambda (AWS, 2026). To eliminate cold starts, enable provisioned concurrency.
- Provisioned capacity: $0.0000041667 per GB-second
- Execution duration (when running): $0.0000097222 per GB-second
- Example: 512MB function, 10 provisioned instances = 5GB provisioned
- Capacity cost: 5GB × 720 hours × 3600 sec × $0.0000041667 = $54/month
- Plus execution costs when invocations actually run
Provisioned concurrency recreates an always-on server but costs 2-3x more than Fargate for equivalent capacity.
Billing granularity — a historical issue resolved:
Lambda changed from 100ms to 1ms billing in December 2020. Billing granularity is no longer a hidden cost on Lambda. Google Cloud Functions Gen1 still bills in 100ms increments — a 20ms invocation bills as 100ms (5x actual cost). If you’re comparing Lambda to GCF Gen1 for short invocations, Lambda wins on billing precision.
Data transfer between functions:
Serverless encourages small, single-purpose functions. If you split a workflow into 5 Lambda functions, data transfer between them adds cost.
- Inter-region transfer: $0.02/GB
- Same region (via S3/SQS): $0.01/GB processing fees
- 1TB processed across 5 functions = 4TB transfer = $40/month
Containers can pass data via local memory or shared volumes without transfer costs.
These hidden costs add up fast. Set up cloud cost alerts to catch NAT gateway and provisioned concurrency charges before they multiply your bill.
How Much Do Real Workloads Cost on Serverless vs Containers?
A nightly ETL job (2 hours/day) costs $3.60/month on Lambda vs $10.49/month on Fargate — Lambda wins at 8% duty cycle. A production API (500 req/sec) costs $450/month on Lambda vs $220/month on Fargate — containers win at 100% duty cycle. Batch processing costs 100x less on ECS Spot than Lambda. Cost winner depends on duty cycle.
Real examples show when each platform wins.
Example 1: Daily ETL job
- Runs 2am to 4am daily (2 hours)
- 1GB memory requirement
- Duty cycle: 8.3% (2 hours / 24 hours)
Lambda:
- Execution: 2 hours × 30 days = 60 hours
- Cost: 60 hours × 3600 sec × 1GB × $0.0000166667 = $3.60
- Requests: 30 × $0.20/1M = negligible
- Total: $3.60/month
Fargate:
- 0.25 vCPU, 1GB memory, 24/7
- vCPU: 0.25 × 720 hours × $0.04048 = $7.29
- Memory: 1 × 720 hours × $0.004445 = $3.20
- Total: $10.49/month
Winner: Lambda (3x cheaper)
Example 2: Production API (1,000 req/min average)
- 1.44M requests per day
- 100ms average response time
- 512MB memory
- Duty cycle: 100% (always processing requests)
Lambda:
- Requests: 43.2M/month × $0.20/1M = $8.64
- Compute: 43.2M × 0.1 sec × 0.5GB × $0.0000166667 = $36
- Total: $44.64/month
Fargate (4 tasks for redundancy):
- 0.25 vCPU, 0.5GB per task
- 4 tasks × ($7.29 + $1.60) = $35.56/month
- Total: $35.56/month
Winner: Fargate (20% cheaper)
Example 3: Batch image processing (10,000 images per day)
- 300,000 images per month
- 3 seconds per image (resize + upload)
- 1GB memory
- Can run on spot instances
Lambda:
- Requests: 300K × $0.20/1M = $0.06
- Compute: 300K × 3 sec × 1GB × $0.0000166667 = $15
- Total: $15.06/month
Scenario A: ECS on Spot (Always-On)
- Runs 24/7 listening to the queue
- Spot instance: $0.0166/hour
- Cost: 720 hours × $0.0166 = $11.95/month
Scenario B: ECS on Spot (On-Demand Spin-up)
- Process 300K images in 8.33 hours total active time using parallel workers
- Spin up container only when batch processing is needed
- Cost: 8.33 hours × $0.0166 = $0.14/month on spot
Winner: ECS Spot On-Demand (100x cheaper)
How Do You Build a Hybrid Serverless and Container Architecture?
Most teams save 46% vs all-serverless by using serverless for event-driven tasks and containers for always-on services. Use serverless for sporadic workloads under 10% duty cycle, containers for steady workloads above 50% duty cycle. Common pattern: containers for APIs and databases, Lambda for cron jobs and webhooks, spot instances for batch processing.
Don’t force everything into one model. Not really an either/or decision.
Hybrid architecture example (e-commerce platform):
Use containers:
- Product API (always-on, 100 req/sec): Fargate $120/month
- User authentication service: Fargate $80/month
- PostgreSQL database: RDS (not serverless): $100/month
Use serverless:
- Order confirmation emails (triggered by purchase): Lambda $2/month
- Nightly inventory sync: Lambda $1/month
- Image optimization on product upload: Lambda $8/month
- Abandoned cart reminders (cron job): Lambda $0.50/month
Use spot instances:
- Monthly analytics report generation: ECS Spot $0.80/month
Total cost: $312.30/month
All-serverless approach: $580/month (APIs on Lambda with provisioned concurrency)
All-container approach: $420/month (scheduled jobs on 24/7 containers)
Hybrid savings: 46% vs all-serverless, 26% vs all-container
Decision matrix:
| Workload Type | Duty Cycle | Invocations/Day | Recommendation |
|---|---|---|---|
| Cron job | <1% | <100 | Lambda |
| Webhook handler | <5% | <5,000 | Lambda |
| Dev API | 10-30% | Variable | Lambda |
| Background jobs | 30-50% | 10K-50K | Evaluate both |
| Production API | 50-100% | >50K | Container |
| Long-running tasks | 100% | N/A | Container |
| Batch processing | Variable | >100K | Spot instances |
I run hybrid architecture for every client. APIs and databases on containers (predictable costs, better performance). Event handlers and cron jobs on Lambda (no idle waste). Batch jobs on spot instances (90% discount). This mixed approach saves 30-40% compared to forcing everything into serverless or containers. Right-sizing your container resources adds another 20-40% — see how to rightsize cloud instances once you’ve chosen your compute model.
FAQ
When should I use serverless vs containers?
Use serverless for sporadic workloads under 10% duty cycle or under 50,000 invocations per day (cron jobs, webhooks, event handlers). Use containers for always-on workloads above 50% duty cycle or over 50,000 daily invocations (production APIs, microservices, databases, background workers). Evaluate both for workloads in the 10-50% duty cycle range. Hybrid approach using both saves 30-40% on average.
What are the hidden costs of serverless?
Hidden serverless costs include NAT gateway fees ($33/month per AZ for VPC access), provisioned concurrency to avoid cold starts ($17-54/month per function), data transfer between functions ($0.01-0.09/GB), and CloudWatch Logs storage ($0.50/GB). These hidden costs can double or triple expected bills, especially for VPC-based or latency-sensitive workloads.
Can I run databases on serverless?
Avoid running databases on serverless functions. Database connections consume memory and take 50-200ms to establish, wasting Lambda execution time and hitting connection limits. Use managed databases (RDS, DynamoDB, Aurora Serverless) or containers running PostgreSQL/MySQL. Aurora Serverless v2 is serverless infrastructure, not serverless functions, and works well for variable database workloads. Redis and MongoDB should run on containers, not Lambda.
How do I calculate if serverless or containers are cheaper?
Calculate duty cycle: (Invocations per day × Average duration × Memory) / (86400 seconds × Container memory). Under 10% duty cycle: serverless wins. Over 50% duty cycle: containers win. 10-50%: compare actual pricing. Use AWS Pricing Calculator for Lambda and Fargate estimates. Include hidden costs: NAT gateways, provisioned concurrency, and data transfer fees.
What about cold starts?
Lambda cold starts average 200-500ms for interpreted languages (Python, Node.js), 1-3 seconds for compiled languages (Java, .NET) (AWS, 2026). Cold starts happen when function hasn’t run recently or scales up. Solutions: use provisioned concurrency ($17-50/month per function), switch to containers (no cold starts), or accept cold starts for non-latency-sensitive workloads. Containers cost more but eliminate cold start unpredictability.
Sources
- Serverless vs Kubernetes Cost Comparison | Gcore — Comprehensive 2026 analysis
- Serverless vs Containers: Which Is More Cost-Effective? | Binadox — Cost comparison framework
- AWS Fargate or AWS Lambda? | AWS Documentation — Official AWS decision guide
- Compare The Cost of AWS Lambda, Fargate, and EC2 | Medium — Real cost calculations with examples
- When Is Serverless More Expensive Than Containers? | Ready, Set, Cloud — Hidden cost analysis including NAT gateways
- Lambda vs. Fargate: The Cost of Running 24/7 | Six Feet Up — Always-on cost comparison
- Evaluating Serverless Vs. Containers | CloudZero — Decision framework with workload patterns
- AWS Lambda Changes Duration Billing from 100ms to 1ms | AWS — Lambda billing granularity change, December 2020
