Skip to content

Instantly share code, notes, and snippets.

@ejlp12
Forked from ross-humphrey/fargate-vs-ec2.md
Last active September 29, 2023 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejlp12/f344fda0d588077ca42114af726f37ad to your computer and use it in GitHub Desktop.
Save ejlp12/f344fda0d588077ca42114af726f37ad to your computer and use it in GitHub Desktop.
πŸ‘©β€πŸŒΎ Fargate Vs EC2

Comparing different launch types of EKS/ECS: Fargate vs EC2

Fargate vs EC2

  • Fargate runs docker containers serverless. Fargate utilizes Docker containers and runs them virtually.
  • Fargate allows you to run containers without having to manage servers or clusters.
  • No need to scale, provision or configure clusters of virtual machines to run containers.
  • No need to choose server types and how they communicate

Two modes

  1. Fargate launch type
  • Pack application in containers, specify the memory/CPU requirements, define IAM or network polocies and launch app.
  1. EC2 launch type
  • Define server level, more granular control over the infrastructure, allows you to find best server for app based on requirementss

Benefits of Fargate:

  • No cluster management
  • Seamless scaling
  • Integration with Amazon ECS
  • Abstracts infrastructure = secure container deployments - embed maximum security within a container.
  • Lower the costs
    • Charges for particular time span app workloads are running
    • Able to determine the right number of containers to run on any given host
    • Roughly 10% cost reduction
  • Reduces complexity

How does Fargate Work?

  • Build the container image in the first step
  • Define resources and images needed for app
  • Launch containers and fargate manages infrastructure
  • AWS runs containers, scales and manages availability

EC2 vs Fargate

Pricing

  • EC2 launch type - billing is based on underlying EC2 instances
  • EC2 launch type - optimize the process by taking advantage of billing models like spot instances / reserved
  • EC2 launch type - customer responsibility to make sure that containers are densely packed onto instances to get max cost benefit . You pay per second - minimum of a minute

Use Cases

  • Workload is consistent for CPU or memory - run EC2

  • Large cluster of EC2 instances is harder to maintain - if you cant handle it use Fargate

  • Small workload - Fargate

  • Small test environment - Fargate

  • Conisstent periodic tasks from a queue - Fargate

  • General purpose workload - Fargate

    You can assume that Fargate will run on general purpose EC2 instances e.g. t or m. AWS didn't specify what instances are used for Fargate, we can assume it can also run at old type of instances eg. t2 or m4

  • Workload with CPU intensive, memory intensive, need high network performance or need special hardware such as GPU - choose EC2.

Fargate Configuration

CPU Memory Values
0.25 vCPU 0.5GB, 1GB, and 2GB
0.5 vCPU Min. 1GB and Max. 4GB, in 1GB increments
1 vCPU Min. 2GB and Max. 8GB, in 1GB increments
2 vCPU Min. 4GB and Max. 16GB, in 1GB increments
4 vCPU Min. 8GB and Max. 30GB, in 1GB increments

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment