All posts

· Max ShipIt

Right-sizing ECS tasks: choosing CPU and memory without guesswork

How to read reservation versus real usage on AWS ECS, pick valid Fargate sizes and stop paying for CPU and memory your tasks never use.

Most ECS task sizes are picked once, when the service is created, and never looked at again. The result is usually tasks that reserve 1 vCPU and 2 GB and use a tenth of it. On Fargate you pay for the reservation, not the usage, so that gap is money spent on nothing.

Reservation vs usage

Two different numbers matter:

  • Reservation is what the task definition asks for: cpu and memory at task level, and optionally per container. On Fargate this is what you’re billed for. On EC2 it’s how much of an instance the task blocks.
  • Usage is what the containers actually consume.

The free CPUUtilization and MemoryUtilization metrics in the AWS/ECS namespace show usage as a percentage of the reservation, per service. A service sitting at 8% CPU and 20% memory is reserving roughly five to ten times what it needs.

For absolute numbers and per-task detail you need Container Insights, which reports CpuUtilized and MemoryUtilized alongside the reserved values.

Which metrics should you size from?

Look at a representative window, at least a week that includes your busiest day:

  • CPU: size for the p95 or p99, not the average. CPU is compressible: a task that hits its limit slows down but keeps running.
  • Memory: size for the maximum plus headroom. Memory is not compressible: a container that exceeds its hard limit is killed with OutOfMemoryError: Container killed due to memory usage (exit code 137).
  • Startup: some runtimes, the JVM in particular, use far more CPU while starting than in steady state. Too little CPU makes startup slow enough to fail health checks.

Which CPU and memory sizes does Fargate support?

Fargate only accepts certain CPU and memory combinations:

vCPUMemory
0.250.5, 1 or 2 GB
0.51 to 4 GB, in 1 GB steps
12 to 8 GB, in 1 GB steps
24 to 16 GB, in 1 GB steps
48 to 30 GB, in 1 GB steps
816 to 60 GB, in 4 GB steps
1632 to 120 GB, in 8 GB steps

If you need more memory but not more CPU, you can raise memory alone within a row. You often don’t have to jump to the next vCPU size.

Container-level limits

Inside a task, each container can set:

  • cpu: a relative share of the task’s CPU. It is not a hard cap, and spare CPU is shared.
  • memoryReservation: a soft limit, used for placement on EC2.
  • memory: a hard limit. Exceeding it kills the container.

A common mistake is a hard memory limit on the app container that’s much lower than the task’s memory. The task has room, but the container gets killed anyway. On Fargate it’s usually simpler to set only task-level memory, plus a small hard limit on sidecars.

A right-sizing routine

  1. List services with average CPU under 20% and memory under 40%.
  2. For each one, check peak memory and p99 CPU over the last one or two weeks.
  3. Pick the smallest valid size that keeps peak memory below about 80% and p99 CPU below about 70%.
  4. Deploy, then watch for out-of-memory stops and slower health checks for a few days.
  5. Repeat every quarter, because traffic changes.

Step 3 as a tool: enter the current size and what the metrics show, and it picks the smallest valid size.

Fargate size picker

Utilization as the free CPUUtilization and MemoryUtilization metrics report it: a share of the current reservation.

Now: 1 vCPU, 2 GB

CPU (p99)15% used
Memory (peak)35% used

$144/month for 4 tasks

Suggested: 0.25 vCPU, 1 GB

CPU (p99)60% used
Memory (peak)70% used

$43/month saves $102

Keeps p99 CPU under 70% and peak memory under 80% of the new size (the line in each bar). Fargate On-Demand, Linux on x86 in us-east-1, October 2026. For other regions, ARM and Spot, use the ECS cost calculator.

Halving a 1 vCPU / 2 GB Fargate task that runs around the clock saves roughly $18 a month per task in us-east-1, at Fargate prices as of November 2026. Across dozens of services with several tasks each, that adds up quickly. The ECS cost calculator shows what a new size saves across your services, on Fargate and on EC2. On EC2, the EC2 instance finder shows which instance types the new sizes fill best.

Don’t forget scaling

Right-sizing and auto scaling interact. If a service scales on CPU at a 50% target, shrinking its tasks makes it run more of them. That’s fine, and often cheaper, but check that the maximum task count still covers your peak.

Smaller tasks that scale out usually beat large tasks that sit idle.