ECS on Fargate or EC2: How to Compare the Real Cost
For ECS, Fargate bills for the CPU and memory your tasks request while they run, and EC2 bills for whole instances whether or not you fill them. Fargate usually wins on small or spiky workloads, and EC2 can win when you keep instances densely packed and busy.
The right answer depends on utilization and how much operations work you want. Here's how to run the numbers yourself.
Vendors Covered in this Article
Disclosure: We may earn a commission if you buy through some links on this page. It doesn't change what we recommend.
How does each option actually charge you?
The billing units differ, which is why quick comparisons mislead.
- Fargate: you pay for the vCPU and memory you request for each task, for the time it runs. Unused capacity inside a task is still billed, but there's no idle server sitting between tasks.
- EC2 launch type: you pay for instances by the hour or second, regardless of how many tasks run on them. You also manage the AMI, patching, scaling groups and capacity.
- Shared discounts: Compute Savings Plans can apply to both, and both offer spot-style capacity for interruption-tolerant work. Confirm current terms before modeling.
Look up current per-vCPU and per-GB rates for your region on the AWS pricing pages. Rates differ by region and CPU architecture, and Arm-based options generally have their own rates.
How to run the comparison
Do this once per service group with real numbers from your metrics:
- List each service's task size (vCPU and memory) and how many tasks run on average and at peak.
- Compute Fargate monthly cost: tasks × (vCPU × vCPU rate + GB × GB rate) × hours running.
- Choose instance types that fit those tasks, then compute how many instances you need at peak, adding headroom for deployments, since rolling updates briefly run old and new tasks together.
- Compute EC2 monthly cost: instances × hourly rate × hours. Add any cost for spare capacity kept for scale-out.
- Add operations time: patching, AMI updates, capacity tuning and on-call for host issues. Price it at your loaded engineering cost.
- Compare totals at your current load and at double the load.
Include the second load level because EC2 gets better as you fill instances, while Fargate scales linearly with tasks.
A worked example
Say you run one API service of 10 tasks, each sized 1 vCPU and 2 GB, and a nightly batch that uses 20 such tasks for two hours. On Fargate, the API bills around the clock for 10 tasks and the batch bills only for its two hours. On EC2, you must size instances for the 30-task batch peak or scale the group up and down each night, and instance startup time and scale-in complexity come into play.
In this shape, the batch's spiky demand favors Fargate, since you avoid paying for idle instances the rest of the day. If instead you had 40 steady tasks running constantly and could pack them onto a few well-utilized instances, EC2 would probably be cheaper on raw compute. The crossover moves with your instance utilization: the emptier your instances, the better Fargate looks.
When should each option win?
Use these rules of thumb, then verify with your numbers:
- Choose Fargate for small teams, uneven load, many small services or anything where engineer time costs more than the compute premium.
- Choose EC2 for large, steady workloads, tasks that need GPUs or specific instance features, or when you can keep instance utilization high and have someone to own the fleet.
- Mix them: ECS lets you run both launch types in one cluster, so put the steady base on EC2 and the spiky work on Fargate.
- Revisit when your load doubles or your team grows, because the answer changes.
Faster delivery matters too. DORA's 2024 report places teams from on-demand deployment to one every one to six months on its frequency scale1, and managed compute that removes host patching leaves more time to ship.
Costs people forget
Beyond compute, include load balancers, NAT gateway traffic, cross-zone data transfer, container registry storage and logs. These are the same on both options, so they don't decide the question, but they can dwarf the difference you're debating.
Also weigh whether ECS itself is right for you: see AWS ECS vs Kubernetes for tech startups and Kubernetes vs AWS ECS vs Nomad. If you're coming from another platform, the Heroku to ECS migration checklist covers the move, and database hosting costs are compared in the managed Postgres calculator.
What Good Looks Like
You know each service's task size, average and peak task count, and instance packing, and you've compared Fargate and EC2 with operations time included.
Building The Capability (5-Stage Skill Ladder)
How to Get Started
Disclosure: We may earn a commission if you buy through some links on this page. It doesn't change what we recommend.
Frequently Asked Questions
Is Fargate more expensive than EC2?
Per unit of compute, often yes when instances are kept full. But Fargate avoids paying for idle capacity and host management, so it can be cheaper for spiky load, small fleets and teams short on operations time.
Can I use Fargate and EC2 in the same ECS cluster?
Yes. Services can use different launch types or capacity providers within one cluster, so you can run steady workloads on EC2 and variable ones on Fargate.
Do Savings Plans apply to Fargate?
Compute Savings Plans can cover both Fargate and EC2 usage. Check the current AWS documentation for terms and eligible options before committing to a plan.
What utilization makes EC2 worthwhile?
There's no fixed number. Model your instances with real packing, deployment headroom and spare capacity, then add operations time. The fuller you can keep instances, the better EC2 looks against Fargate.
Sources
Where we quote a benchmark, we show its source. Other figures in this guide are estimates or general guidance, so check them against your own numbers.
- Deployment frequency by DORA performance cluster (max days between deploys). DORA Accelerate State of DevOps 2024 (Google Cloud), cluster table via Octopus Deploy analysis, 2024.
Related Guides
AWS ECS vs Kubernetes for Tech Startups: Container Orchestration Compared
Compare AWS ECS and Kubernetes for tech startups: DevOps headcount spend, Fargate serverless containers, operational complexity, and deployment speed.
Kubernetes vs AWS ECS vs HashiCorp Nomad: Container Platforms Compared
Compare Kubernetes, AWS ECS, and HashiCorp Nomad for container orchestration, DevOps overhead, cluster autoscaling, deployment velocity, and hosting COGS.
Moving From Heroku to AWS ECS: A Checklist by Stage
A staged checklist for moving an app from Heroku to AWS ECS: mapping dynos and add-ons, containers, database cutover, DNS and a rollback plan.
Comparing Managed Postgres Costs: Supabase and Amazon RDS
Compare managed Postgres cost between Supabase and Amazon RDS with a worksheet covering compute, storage, backups, high availability, bandwidth and staff time.
Kubernetes vs. ECS When You Deploy Into a Client's Account
A custom software shop's infrastructure choice has to survive the handoff at the end of the contract. Here's a worked example for picking Kubernetes or ECS.
Moving a Next.js App From Vercel to AWS: Options and Steps
Decide whether and how to move a Next.js app from Vercel to AWS: container versus serverless options, caching, images, previews, DNS cutover and rollback.