Fargate vs. EC2: What is the difference and which is best for ECS? - Spot.io

Fargate vs. EC2: What is the difference and which is best for ECS?

Reading Time: 6 minutes

AWS Fargate and EC2 are both cloud services for managing and scaling containers. They use different models for running containers on AWS. Fargate is a serverless environment that allows you to run containers without the need to manage EC2 instances. EC2 lets you deploy and manage your own EC2 instances to run containerized applications.

Some of the key differences between Fargate and EC2 include their different use of infrastructure, different pricing model and cost, and differing security features.

In this blog post, we’ll explore these two services, and explain how they can be used to run containers in Elastic Container Service (ECS), Amazon’s lightweight container orchestration system.

 

What is Fargate?

Fargate is a serverless environment that allows users to run containers without managing the underlying instances. With Fargate, AWS manages the host to run the containers. Users don’t need to worry about instances or servers, they only need to define resource requirements. AWS Elastic Container Service (ECS) and AWS Elastic Kubernetes Service (EKS) both support Fargate as well as Fargate Spot (more on this below).  

 

What is EC2?

EC2 is an on-demand computing service on the AWS cloud platform. With EC2, you manage and deploy your own compute instances (also known as virtual machines). EC2 can be used to run a variety of workloads, and one common workload is containerized applications.

 

Fargate vs. EC2: What are the differences?

Here are some differences between Fargate and EC2:

  • Infrastructure: Fargate runs on EC2 instances, but you don’t need to manage or provision EC2 instances yourself.
  • Pricing model: Fargate charges for usage on a per-minute basis, with charges varying based on the amount of virtual CPU (vCPU) and memory your containers use. With EC2, you pay for only the EC2 compute capacity and Elastic Block Storage (EBS) capacity that you use.
  • Comparative cost: The per-hour cost for instances is higher with Fargate than with EC2. Fargate is typically more expensive than EC2 when running the same workloads, but there are ways to optimize AWS Fargate costs that make Fargate significantly cheaper.
  • Security: Running containers on EC2 is generally considered more secure compared to Fargate.
  • Fractional vCPU: EC2 does not let you use instances with less than one vCPU, while Fargate offers you a minimum of 0.25 vCPU.

 

What is ECS?

AWS ECS (Elastic Container Service) is a managed container orchestration platform that enables fast deployment and scaling of containerized workloads. With ECS, users don’t have to configure or manage their own container management as ECS runs and manages containers in a cloud cluster. ECS supports EC2 launch types, as well as AWS Fargate. 

 

ECS with EC2 instances

As a managed service for container orchestration, there are many aspects of ECS that help to simplify the management of containers, including cluster creation, setup and maintenance. However, ECS doesn’t automate everything about cluster management. It still leaves the compute layer visible, requiring users to provision, scale, monitor, secure and manage the underlying EC2 instances themselves. ECS capacity providers can be used to manage infrastructure of tasks through the default strategy, or users can define their own. 

While ECS users have more granular control over cluster operations, it does come at the cost of a management tax. When ECS containers are deployed to EC2 instances, it’s up to the user to determine what type of instance to use, and when to scale them. (Scaling presents its own challenges, which you can read about here.)

 

ECS with AWS Fargate

Running ECS with Fargate however, eliminates the need to manually provision, scale and manage compute instances. Users create a cluster, add workloads to it and specify resource requirements (CPU and memory), and when ECS containers are deployed, Fargate will launch, run and manage pre-configured servers that meet container requirements. These time-saving benefits eliminate the operational burden of managing compute, but the trade-off is limited features, less control and potentially higher costs. 

 

What are the limitations and challenges of using Fargate with ECS?

By giving control of infrastructure to Fargate, users are limited in what they can customize and configure. Some of the limitations of using ECS with the Fargate launch type include:

  • No option to choose specific instance types
  • Running workloads like Daemonsets or privileged pods are restricted
  • Many ECS task definition parameters are not valid with Fargate (see here for a full list of unsupported task definitions)
  • No support for GPU
  • Classic load balancers are not supported, only Application and Network load balancers can be used to distribute workloads
  • No support for EBS 

 

ECS and Fargate compute pricing

Using ECS is free of charge, with users paying for compute costs by the hour. EC2 launch type pricing is based on CPU and memory of each instance type, and is fixed regardless of whether or not it is fully utilized. Fargate pricing is based on task size, but task definitions are limited by the configurations supported by Fargate, and the per-hour cost for instances is higher than with EC2. With Fargate, you’re billed only for how many CPU cores and gigabytes tasks use, which helps to ensure you aren’t wasting money on resources that go unused.  

Both ECS and Fargate offer on-demand and spot instances, with spot instances delivering a saving of up to 90% with the caveat that these instances can be terminated at any time with short notice. 

Related content: Read our guide to AWS EMR pricing

 

When does it make sense to use ECS with Fargate?

ECS is a great option when you have unique requirements such as running machine learning tasks on GPU instances, need persistent storage with EBS volumes, or more control of networking with alternate modes such as ‘bridge’ or ‘host.’ ECS delivers more control over the infrastructure, but the trade-off is the added management that comes with it.

Fargate is the better option for ease of use as it takes infrastructure management out of the equation allowing you to focus on just the tasks to be run. It works great for most workloads and enables a faster pace of operations. This is an important consideration for teams that are looking to move faster, be agile, and innovate.

No decision can ever be made without taking cost into consideration, and on average, the cost of running workloads on Fargate is three times more than running the same workloads on EC2.  While it’s possible to run spot instances with Fargate, AWS doesn’t have an SLA for these and they can be taken away with little to no warning. Moreover, using Fargate means that customers also can’t make use of their existing reserved instances. 

 

What are the alternatives to ECS and Fargate?

If looking to stay within the AWS cloud, the closest option to self-managed ECS and ECS on Fargate is AWS EKS. EKS follows the Kubernetes model of managing containers in pods unlike ECS where tasks are the focus. If your organization is still early in its Kubernetes journey, you can avoid the steep learning curve that comes with EKS and opt for the simpler container-centric ECS. Outside of AWS, Azure and Google Cloud have similar options such as Azure Container Instances (ACI), Azure Kubernetes Service (AKS) and Google Kubernetes Engine (GKE). 

 

Spot Ocean: The turnkey and affordable alternative to Fargate

Another alternative to Fargate is Spot by NetApp’s Ocean which delivers serverless management of containers running on AWS ECS, EKS and other container orchestration solutions. In this sense Ocean is similar to Fargate in that it takes the pain out of managing compute ECS infrastructure. However, Ocean goes beyond this to offer a high availability SLA for workloads despite running them on spot instances. Ocean is able to preempt termination of spot instances and gracefully manage the migration of these workloads to other spot instances, available RIs and Savings Plans and if needed, to on-demand instances. In this way Ocean brings together the best of both worlds – the ease of serverless while maintaining full access and control of the underlying infrastructure, along with and the extreme cost savings of spot instances. 

 

Ocean benefits

Ocean automates and simplifies container infrastructure management, continuously optimizes resource utilization and efficiency, and reduces cloud compute costs by up to 90%.  

Ocean provides these benefits in two dimensions: 

Infrastructure Optimization 

  • Provisions nodes that perfectly match container resource requirements with intelligent bin-packing for optimal workload allocation.     
  • Analyzes task utilization for right sizing container resource requirements.    
  • Eliminates tedious and time-consuming compute infrastructure management.

Pricing Optimization

  • Reliably runs mission-critical and production container workloads on low-cost spot instances with enterprise-level SLA for high availability.  
  • Guarantees workloads continuity with predictive algorithms allowing for proactive draining and replacement of at-risk spot instances along with automated fallback to on-demand instances (or available Savings Plans and RIs) as needed. 

 

Conclusion

For organizations looking to simplify the management of containers in the cloud AWS ECS offers a capable managed service that greatly simplifies operations. To further simplify container operations, ECS running on Fargate can deliver a serverless experience that abstracts away infrastructure management, albeit with a few constraints in data storage and networking.

Spot Ocean is an alternative to ECS and Fargate which combines the ease of serverless with the cost savings of spot instances. The key benefit of Ocean is that it guarantees a high availability SLA despite running on spot instances – something that ECS and Fargate do not offer.

Whether you currently use the self-managed ECS, or the serverless Fargate, Spot Ocean is a step up from these services, able to simplify container management, deliver high availability, and do all this at almost half the cost.