Tech Duel
AWS Lambda vs ECS: which compute model is right for your workload?
Lambda gives you serverless execution, zero infrastructure, pay per invocation, scales instantly. ECS gives you container control, always-on, no cold starts, suited for long-running workloads. The right choice hinges on your traffic pattern, execution duration, and how much cold start latency your users can tolerate.
Last reviewed: June 2025
When to choose Lambda vs ECS
Choose Lambda when…
- Your workload is event-driven (S3, SQS, EventBridge, API Gateway)
- Traffic is spiky, intermittent, or unpredictable, you need to scale to zero
- Execution completes in under 15 minutes per invocation
- Cold start latency of 100ms–2s is acceptable for your use case
- You want zero infrastructure management
Choose ECS when…
- Your service must run continuously (daemons, WebSocket servers, long polling)
- Cold starts would cause unacceptable user experience
- Execution time exceeds 15 minutes (Lambda's hard limit)
- You need persistent TCP connections (gRPC, database connection pools)
- Large container images or custom runtimes are required
That's the generic picture. Your traffic pattern, cold start tolerance, and execution duration will tip this one way or the other. ↓
Lambda vs ECS: cold starts in production, the real numbers
Cold start latency is the most misunderstood dimension of the Lambda vs ECS decision. A cold start occurs when Lambda needs to initialize a new execution environment, provisioning compute, downloading your deployment package, starting the runtime, and executing your initialization code outside the handler. The duration depends heavily on runtime, package size, and network configuration.
By runtime, typical cold start times break down as follows: Node.js functions cold start in 100–500ms; Python in 100–400ms; Go in 50–200ms (the fastest native runtime); Java without SnapStart in 1–5 seconds (the heaviest JVM initialization). These figures assume a small to medium deployment package deployed as a zip archive, no VPC attachment, and a function that hasn't been idle for more than 15 minutes.
VPC attachment historically added a significant cold start penalty, 1–10 additional seconds, because Lambda needed to provision an elastic network interface. AWS addressed this in 2019 with Hyperplane ENIs, which pre-provision and cache network interfaces across functions. The penalty today is roughly 100–500ms for VPC cold starts, down from multiple seconds. Still, if you need to access a VPC resource (RDS, ElastiCache), expect cold starts to run at the higher end of the range for your runtime.
AWS provides two mechanisms to eliminate cold starts. Provisioned Concurrency pre-initializes a specified number of execution environments, keeping them warm and ready to serve requests instantly. The cost is approximately $0.015 per GB-hour of provisioned memory, on top of normal execution charges. A common production pattern is to apply Provisioned Concurrency only on critical-path functions, the customer-facing API endpoint, while letting background workers and async processors cold-start freely. Lambda SnapStart (currently Java only) snapshots the initialized runtime state after the init phase and restores from that snapshot on cold start, typically bringing Java cold starts under 1 second without the ongoing cost of Provisioned Concurrency.
The honest bottom line: for most web APIs serving end users, a 300ms occasional cold start is barely perceptible and fully acceptable. For financial transaction processing, real-time gaming, or high-frequency trading systems where every millisecond counts, the cold start is a hard blocker, and ECS is the right answer.
Lambda vs ECS: cost comparison at different scales
The Lambda and ECS cost models are structured so differently that the cheaper option can flip depending entirely on request volume and execution duration. Getting the cost comparison right requires running the numbers for your specific workload.
Lambda's pricing has two components: request charges ($0.20 per 1 million requests) and compute charges ($0.0000166667 per GB-second). Lambda includes a permanent free tier of 1 million requests and 400,000 GB-seconds per month, enough to run a lightly used API or background job for free indefinitely. At 10 million requests per month with an average execution duration of 200ms at 512MB memory allocation, the math works out to approximately $1.60 in compute charges plus $2.00 in request charges, totaling roughly $3.60 per month.
The equivalent ECS workload running on Fargate with 0.25 vCPU and 512MB of memory running continuously costs approximately $9 per month for compute alone, before data transfer, load balancer, or ECR storage charges. At this scale, Lambda wins decisively, and the workload may even qualify for the free tier.
Scale that workload up to 100 million requests per month at the same execution profile: Lambda compute comes to roughly $16 plus $20 in request charges, approximately $36 per month. A reserved Fargate task at 0.5 vCPU and 1GB memory running continuously with a 1-year reservation costs around $12 per month. At this volume, ECS wins on raw compute cost by a factor of three.
One cost that frequently surprises teams building Lambda APIs: API Gateway charges $3.50 per million API calls on the REST API tier ($1.00 per million on HTTP API). At 10 million requests per month, API Gateway adds $35 or $10 to the bill, often more than the Lambda compute cost itself. Teams running high-volume Lambda APIs typically replace API Gateway with an Application Load Balancer ($0.008 per LCU-hour) to reduce per-request costs at scale.
The general principle: Lambda is cheaper at low-to-moderate volume (under 50–100 million requests per month at typical durations). ECS on reserved Fargate or EC2 wins at sustained high throughput. The crossover depends on your average execution duration and memory allocation.
Lambda vs ECS: hybrid architectures
In practice, the Lambda vs ECS decision is rarely an either/or choice at the application level. Most mature production AWS architectures use both services simultaneously, each handling the workloads they're best suited for. The real question is often which service should own which part of your system.
The most common hybrid pattern is ECS for synchronous customer-facing APIs and Lambda for asynchronous event processing. Your ECS service handles low-latency HTTP endpoints where cold starts would hurt user experience. Lambda handles the surrounding event-driven workloads: S3 object processing when files are uploaded, SQS consumers that process job queues, EventBridge rules that react to state changes, and CloudWatch scheduled events that replace cron jobs. This combination gives you consistent latency on the critical path and cost efficiency on the async work.
Another common pattern pairs Lambda for scheduled batch jobs and ECS for the core application. Rather than running a long-lived scheduled task container, a Lambda function on a cron EventBridge rule kicks off nightly reports, data exports, or cache warmup routines, then terminates. No idle container cost, no scheduler infrastructure to maintain.
AWS Step Functions is a natural complement to Lambda-heavy architectures. It orchestrates multi-step workflows across multiple Lambda functions, retry logic, branching, parallel execution, and error handling, without any of that logic living in application code. Step Functions works with both Lambda and ECS tasks, making it the right abstraction layer when a workflow spans both compute models.
Amazon EventBridge serves as the event bus that routes events between Lambda functions, ECS services, SQS queues, and external destinations. A single EventBridge event can trigger a Lambda function for lightweight processing, put a message on an SQS queue consumed by an ECS service, and archive to S3, all simultaneously. This decouples your compute choices from your event routing, making it easy to migrate a Lambda consumer to ECS later if throughput demands grow.
The Lambda vs ECS choice is a per-workload decision, not a per-application one. Most teams end up using both, and the teams that try to force everything into one model typically end up paying more or operating more complexity than necessary.
Get your personalized recommendation
The table above is the same for everyone. Your traffic pattern, execution duration, and cold start tolerance are specific to you. Answer 5 quick questions and we'll generate a recommendation grounded in your actual workload.
Question 1 of 5
Recommendation
AWS Lambda
confidence score
Based on your traffic pattern, execution duration, and cold start tolerance, Lambda is the better fit. The pay-per-invocation model will be significantly cheaper at your traffic volume, and the event-driven architecture aligns with your workload…
Sign up to unlock your report
Your answers are saved. Create an account, add credits, and your personalized Lambda vs ECS report generates instantly.
Continue with Googleor
Sign up with email1 personalized report uses 1 credit · Credit packs from $10 · No subscription required
Common questions about Lambda vs ECS
Should I use AWS Lambda or ECS?
Lambda is the right default for event-driven workloads, S3 triggers, API Gateway endpoints, SQS consumers, and scheduled jobs, especially when traffic is spiky or intermittent. ECS is better for long-running services, sustained high-throughput APIs, workloads where cold starts are unacceptable, or applications that need persistent connections like WebSockets or gRPC.
What is the difference between Lambda and ECS?
AWS Lambda is a serverless compute service, you deploy code, AWS runs it in response to events, and you pay per invocation and duration in milliseconds. Amazon ECS is a container orchestration service, you run Docker containers on EC2 instances or AWS Fargate. Lambda scales from zero instantly; ECS containers are always running or pre-provisioned on Fargate.
Is Lambda cheaper than ECS?
It depends on traffic volume. Lambda is dramatically cheaper for spiky or low traffic, you pay nothing when idle. At sustained high throughput (tens of millions of requests per month), ECS on Fargate or reserved EC2 often wins on cost. The Lambda free tier (1M requests and 400,000 GB-seconds per month) makes Lambda free for many low-volume workloads.
What is AWS Fargate?
Fargate is the serverless compute engine for ECS and EKS. Instead of managing EC2 instances, you define the vCPU and memory for each task and AWS runs the container without you managing the underlying infrastructure. Fargate gives you long-running ECS containers without the EC2 operational overhead.
When should I use Lambda with API Gateway vs ECS for an API?
Lambda + API Gateway is ideal for APIs with variable or low traffic (you pay per request, no idle cost), straightforward request/response patterns, and execution time under 29 seconds. ECS is better for APIs with sustained high traffic, sub-100ms cold-start requirements, WebSocket or streaming endpoints, or complex connection pooling to databases. Note that API Gateway itself charges $3.50 per million requests, often more than the Lambda compute at scale.