ECS vs. Fargate: What's the difference?

Michael WittigUpdated 26 Nov 2020

When discussing options to run Docker on AWS, I’m often asked about the differences between ECS and EKS or Kubernets. However, lately, a new question arises: What’s the difference between ECS and AWS Fargate? In this blog post, you get the answer. You also learn about the advantages and disadvantages of both options.

ECS vs. Fargate: What's the difference?

Do you prefer listening to a podcast episode over reading a blog post? Here you go!

To understand the difference, let’s divide the ECS service into two responsibilities:

  1. Managing the lifecycle and placement of tasks
  2. Running containers

Managing the lifecycle and placement of tasks

First, ECS is responsible for managing the lifecycle and placement of tasks. A task is usually made of one or two containers that work together, e.g., an nginx container with a php-fpm container. You can ask ECS to start or stop a task, and it stores your intent. However, ECS does not run or execute your container. ECS only provides the control plane to manage tasks. So, who runs the containers?

Running containers

To run containers, you have two options. You can use ECS container instances, or you can use Fargate. Both options work together with ECS. The following figure demonstrates the difference.

ECS: container instance versus Fargate

ECS container instance

An ECS container instance is nothing more than an EC2 instance that runs the ECS Container Agent. The EC2 instance is owned and managed by you. The instance appears in the list of EC2 instances like any other EC2 instance. The ECS Container Agent regularly polls the ECS API if new containers need to be started or stopped. Usually, you run a cluster of container instances in an auto-scaling group. ECS is free of charge. You only pay for the EC2 instances. The downside is that you have to scale, monitor, patch, and secure the EC2 instances yourself. Especially the scaling is not easy because:


Looking for a new challenge?

  • tecRacer

    Cloud Consultant • AWS Migrations

    tecRacer • Premier AWS Consulting Partner • Germany, Austria, Portugal, and Switzerland
    Assessment Transformation Change Management
  • DEMICON

    Senior Lead Cloud Solutions Architect AWS

    DEMICON • AWS Advanced Consulting Partner • Remote (Europe)
    GitLab Terraform K8s EKS Lambda Python Go

  • There is no obvious metric to scale the cluster and no integration to scale when the task placement fails because of insufficient capacity.
  • The auto-scaling group and ECS are not aware of each other, making task deployments very hard during cluster scale in or rolling updates via CloudFormation (Capacity Providers address this issue but are not ready for prime time yet).
  • You have to scale down without killing running tasks, which is an even more significant challenge for long-lived tasks.

Even the AWS reference architecture does not include auto-scaling for the cluster. Check out our reference architecture with auto-scaling if you are interested.

An ECS container instance can run on Linux or Windows. Unused CPU shares can be used by other containers if available.

Fargate

AWS Fargate manages the task execution. No EC2 instances to manage anymore. You pay for running tasks. That’s it. As easy as it sounds.

Each task that runs in Fargate comes with a dedicated Elastic Network Interface (ENI) with a private IP address. All containers of the same task can communicate with each other via localhost. Inbound and outbound task communication goes through the ENI. A public IP address can be enabled as well.

Comparison

ECS container instance Fargate
Host OS Linux, Windows Linux
Max vCPU 448 4
Max Memory 26 TB 30 GB
CPU bursting Linux: yes; Windows: no no
Pricing per running EC2 instance per running task
Discounts Reserved Instances, Savings Plans, Spot Compute Savings Plans, Spot
Operational effort high low
EFS integration yes yes
EBS integration hacky but possible 1 no
Networking options multiple 2 ENI per task

Summary

ECS or Fargate is not the right question to ask. The question is whether to use container instances or Fargate. What ECS calls a container instance is known as a worker node in Kubernetes/EKS.

We learned it the hard way. Scaling container instances is a challenge. That’s why we recommend using Fargate. Fargate is much easier to operate. Use it if possible (see networking, vCPU, memory, host OS, and EBS limitations).

Want to get started with AWS Fargate quickly? Check out our book and online seminar Rapid Docker on AWS.


  1. 1. https://aws.amazon.com/blogs/compute/amazon-ecs-and-docker-volume-drivers-amazon-ebs/
  2. 2. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#network_mode

Become a cloudonaut supporter

Michael Wittig

Michael Wittig ( Email Twitter LinkedIn Mastodon )

We launched the cloudonaut blog in 2015. Since then, we have published 366 articles, 60 podcast episodes, and 58 videos. It's all free and means a lot of work in our spare time. We enjoy sharing our AWS knowledge with you.

Please support us

Have you learned something new by reading, listening, or watching our content? With your help, we can spend enough time to keep publishing great content in the future. Learn more

$
Amount must be a multriply of 5. E.g, 5, 10, 15.

Thanks to Alan Leech, Alex DeBrie, ANTHONY RAITI, Christopher Hipwell, e9e4e5f0faef, Jason Yorty, Jeff Finley, jhoadley, Johannes Grumböck, Johannes Konings, John Culkin, Jonas Mellquist, Jonathan Deamer, Juraj Martinka, Ken Snyder, Markus Ellers, Oriol Rodriguez, Ross Mohan, Ross Mohan, sam onaga, Satyendra Sharma, Simon Devlin, Thorsten Hoeger, Todd Valentine, Victor Grenu, waldensystems, and all anonymous supporters for your help! We also want to thank all supporters who purchased a cloudonaut t-shirt.