Running containers on ECS: Should you use EC2 or Fargate?

Containerization of applications brings many benefits to software development, enabling speed, agility, and flexibility. The maturation of the container ecosystem has accelerated quickly in the last few years, leaving users with a multitude of choices when it comes to tooling and services. The major cloud providers (AWS, Azure, and Google Cloud) have introduced services specifically to help users run their containerized applications more efficiently and effectively. In this blog post, we’ll explore two major services provided by AWS for containers – Elastic Container Service (ECS) and Fargate.

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. 

What is Fargate?

AWS Fargate is a serverless compute engine for containers that abstracts the underlying infrastructure and can be used to launch and run containers without having to provision or manage EC2 instances. Users don’t need to worry about instances or servers, they 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).  

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 Fargate?

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 worloads
  • No support for EBS 

ECS & 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. 

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). 

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 is 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.