The Cost of Hosting an App in AWS Fargate
Tags: aws, fargate, cloud, awsfargate
Published: 2023-09-04 22:27:53

As serverless computing becomes mainstream, more enterprises are embracing this technology in recent times. While implementing this serverless computing technology, Fargate pricing is something organizations should be careful of. This blog uncovers actual AWS Fargate pricing costs to host an app.

## What is Fargate?
Fargate is a serverless compute engine that lets you deploy and manage apps, APIs, and [microservices](https://www.clickittech.com/devops/microservices-vs-monolith/?utm_source=devto&utm_medium=referral#1) without the need to manage the underlying infrastructure. It also optimizes costs by only paying for the resources used. 

With Fargate, you simply package your app into containers, define Memory/CPU configuration and IAM policies, and run the application. Fargate makes scaling simple and easy. It works with Amazon Elastic Kubernetes Service (EKS) and Amazon Elastic Container Service (ECS). 

## Fargate Architecture


![Fargate Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4aez7terxll5fitdb63.png)

**Why Bother about Fargate Pricing?**
Why bother about AWS Fargate pricing when it is a fully-managed serverless offering? You should! 

- Because AWS handles the hardware of the container platform and not the container/pod size.
- Because AWS automatically scales the number of containers/pods and not their sizes.
- Because striking a balance between cost and performance is important, using the right-sized containers for the right tasks.
- Because the application’s resource footprint, web server, computing platform, and libraries determine the right size of the containers/pods.

## AWS Fargate Pricing: Real Costs and Pricing Structure
AWS does not charge any upfront costs for Fargate. You only need to pay for the resources used. 

Primarily, Fargate pricing is based on the requested vCPU and memory capacities. However, other dimensions affect this price.

Fargate pricing is based on five independently configurable dimensions:

1. vCPU
2. Memory
3. Operating System
4. CPU Architecture
5. System Resources

For instance, AWS charges $0.04048 per hour for one vCPU and $0.004445 per 1 GB per hour in the US East Ohio region for Linux /x86 architecture. When ARM CPU architecture is involved, the prices change to $0.03238 per vCPU per hour and $.00356 per GB per hour. 

For Windows / x86, the price is $0.09148 per vCPu per hour and $0.01005 per GB per hour. There’s also an additional OS license fee of $0.046 per vCPu per hour.


![Real costs and structure of fargate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qh9zspbesl9mpgtsodci.png)

As you can see from the table above, the price of vCPU and memory varies with region, CPU architecture, and operating system. It is important to note that Windows OS and ARM CPU architecture options are available only for [Amazon ECS](https://www.clickittech.com/aws/amazon-ecs-vs-eks/?utm_source=devto&utm_medium=referral#whatisecs) and for selected regions. So, it’s important to consider all these aspects before calculating the Fargate cost.

**Fargate Storage**

Each ECS task hosted on the Fargate platform comes with a default ephemeral storage of 20 GiB. If a task needs additional storage, you can purchase ephemeral storage for up to 200 GiB per task. 

While the first 20 GiB ephemeral storage is free, every GiB after that value is charged based on the AWS region. For instance, AWS charges $0.000111 per GB per hour for Fargate ephemeral storage in the US East Ohio region. If a task uses 30 GB of ephemeral storage, only 10 GB is chargeable. 

## AWS Fargate Pricing Examples
### 1) Small Apps
Consider a small app with concurrent users of less than 20 wherein each user consumes less than 50 MB over a period of 5 minutes. 

The first step is Capacity Planning: 

1.Identify delta memory consumption for each user and multiply it with the concurrent users at the development stage using tools such as CloudWatch Application Insight.

Example: 20  concurrent users x 50 MB = 1000 MB

2.Allocate buffer memory for peak requirements = 500 MB

3.Allocate another 500 MB for container monitoring process consumption, such as Amazon CloudWatch, Grafana, or Prometheus. 

4.The total memory comes to around 2 GB 

5.Determine the corresponding vCPU value for 2 GB: 0.5 vCPU

For capacity planning, assign these values as a starting point:

![Fargate example 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jwr17sbrtt7d8e40cssb.png)

For two tasks with 1 GB memory and 0.25 vCPU each, the total comes down to 2 GB and 0.5 vCPU.

When you calculate the average monthly price:

**- No. of Tasks:** 2 per day = (730 hours in a month / 24 hours in a day) = 60.83 per month

**- Task Duration:** 5 minutes = 0.09 hours

**- vCPU Charges (0.5 vCPu)**  = 60.83 tasks x 0.50 vCPU x 0.09 hours x 0.04048 USD per hour = 0.11 USD for vCPU hours

**- Memory Charges (2 GB):** 60.83 tasks x 2.00 GB x 0.09 hours x 0.004445 USD per GB per hour = 0.05 USD for GB hours

**- Ephemeral Storage Charges:** 20 GB – 20 GB (no additional charge) = 0.00 GB billable ephemeral storage per task

Fargate Cost (Monthly): 0.11 USD for vCPU hours + 0.05 USD for GB hours = **0.16 USD**

 
### 2) Medium-sized Apps
A medium-sized app has 50 concurrent users wherein each user consumes memory between 50MB and 80 MB over a period of 5 minutes.

Following the steps mentioned above, assign these values as a starting point:


![Fargate example 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ih57p7xxqtipuh33wx9c.png)

When you calculate the average monthly price:

**- No. of Tasks:** 5 per day = (730 hours in a month / 24 hours in a day) = 152.08 per month

**- Task Duration:** 5 minutes = 0.09 hours

**- vCPU Charges (2 vCPu)**  = 152.08 tasks x 2 vCPU x 0.09 hours x 0.04048 USD per hour = 1.11 USD for vCPU hours

**- Memory Charges (6 GB):** 152.08 tasks x 6 GB x 0.09 hours x 0.004445 USD per GB per hour = 0.37 USD for GB hours

**- Ephemeral Storage Charges:** 30 GB – 20 GB (no additional charge) = 10.00 GB billable ephemeral storage per task
152.08 tasks x 10.00 GB x 0.09 hours x 0.000111 USD per GB per hour = 0.02 USD for ephemeral storage GB hours

Fargate Cost (Monthly): 1.11 USD for vCPU hours + 0.37 USD for GB hours + 0.021 USD for ephemeral storage GB hours = **1.50 USD**

### 3) Large-sized Apps
A large-sized app has more than 100 concurrent users wherein each user consumes memory of more than 100 MB over a period of 5 minutes.

Following the steps mentioned above for small apps, assign these values as a starting point: 


![Fargate example 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74u9i2szkpjh9ihr6nsn.png)

When you calculate the average monthly price:

**- No. of Tasks:** 5 per day = (730 hours in a month / 24 hours in a day) = 152.08 per month

**- Task Duration:** 5 minutes = 0.09 hours

**- vCPU Charges (4 vCPu)**  = 152.08 tasks x 4 vCPU x 0.09 hours x 0.04048 USD per hour = 2.22 USD for vCPU hours

**- Memory Charges (16 GB):** 152.08 tasks x 16 GB x 0.09 hours x 0.004445 USD per GB per hour = 0.97 USD for GB hours

**- Ephemeral Storage Charges:** 50 GB – 20 GB (no additional charge) = 30.00 GB billable ephemeral storage per task
152.08 tasks x 30.00 GB x 0.09 hours x 0.000111 USD per GB per hour = 0.05 USD for ephemeral storage GB hours

Fargate Cost (Monthly): 2.22 USD for vCPU hours + 0.97 USD for GB hours + 0.05 USD for ephemeral storage GB hours = **3.24 USD**

## How To Reduce Costs in AWS Fargate?
Here are the top four ways to reduce costs in AWS Fargate:

**1) AWS Savings Plan:** Amazon Savings Plan helps you gain a discount of up to 72% on compute workloads regardless of the region, operating system, tenancy, size, and instance family. It automatically applies the discount to your EC2 instances and Fargate usage. However, the plan requires a 1-3 year commitment for a specified amount of usage (billed per hour). 

Once subscribed, the prices stay the same for the entire contract period, regardless of changing on-demand prices. There are different payment modes, such as No Upfront, Partial Upfront, and Full Upfront. 

Taking a cue from the AWS Cost Explorer in the form of recommendations, you can plan AWS Savings Plan while proactively managing the plan based on budget alerts and performance monitoring reports. When you run out of the subscription, the regular on-demand prices are automatically applied to your billing.

**2) Fargate Spot Instances:** AWS Fargate Spot is a useful feature for interruption-tolerant Amazon ECS tasks wherein you can gain a discount on Fargate pricing of up to 70%. On-demand and Spot instances look similar in most aspects but vary in two areas: the perGB and per vCPU costs vary up to 70%, and tasks are interruptible. 

The price is the same in all availability zones but varies throughout the day. AWS provisions spare capacity in the cloud, which is the reason for that jaw-dropping price. 

Please note that AWS removes these instances when it needs the capacity back with a 2-minute notification. As such, you should run interruption-tolerant tasks to enjoy this discount while not getting a hit on availability. 

It is important to terminate tasks gracefully. Tasks such as genome processing, image rendering, CI/CD, stateless web servers, and containerized workloads are a few examples that best suit the Fargate spot pricing model.

Fargate spot prices are charged per second but require a minimum of 1 minute usage. There are no upfront charges, and you only pay for the resources used. The billing starts when a container image starts getting downloaded till the termination of that task. 

**3) Right-sizing Fargate tasks:** When it comes to cost optimization, right-sizing Fargate tasks hold the key. Overprovisioning Fargate tasks is a common mistake that increases cloud costs.

When you choose smaller containers in more numbers, considering the lower costs, you should also consider the cold starts and performance issues. Alternately, when you choose large-sized containers in fewer numbers, it will result in resource wastage. Ideally, the tasks should use at least 85% of computing resources. 

To right-size Fargate tasks, 

1.Check out the memory usage in the development stage. CloudWatch Application Insight gives you an idea of the memory utilization of an app. 

2.Identify the concurrent users and multiply those values accordingly.

3.Determine the corresponding vCPU values for that task.

AWS recommends the following computing configuration for effective capacity planning. 


![Fargate pricing cloud computing configuration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pqra1aepctw1xm0rv6j1.png)


Source: [Amazon ECS on AWS Fargate – Amazon Elastic Container Service](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html#fargate-tasks-size)

4.Run load testing to evaluate the performance of that configuration for the assigned load.

5.Fine-tune resource allocations.

6.Define auto-scaling policies that balance cost and performance. As a best practice, check out the baseline performance of the application and its performance under load to rightly configure auto-scaling policies.

**4) Tagging Resources:** To gain greater visibility into workloads while optimizing costs, tag your AWS Fargate resources such as task definitions, clusters, container instances, services, etc. It will help you identify orphaned resources running unnoticed to reduce cloud waste. 

Tagging your resources facilitates fine-grained resource-level permissions and allows you to systematically manage the costs of workloads running across various teams, environments, and business units.

## AWS ECS Costs – Without Fargate
AWS Elastic Container Service (ECS) offers two launch types, namely EC2 instance and Fargate. When you use an EC2 launch type, you’ll be paying a fixed price for the memory and CPU provisioned for that instance type, regardless of the percentage of resource usage. 

On the contrary, the Fargate cost is based on the resource usage for a single task, allowing you to right-size the instance.


![ECS with EC2 Launch Type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9c79d1m3b97s1tudtsa.png)


Let us take the popular m5.xlarge EC2 instance choosing the ‘Compute Savings Plan’ with a 1-year commitment and no upfront charges. It comes with a fixed configuration of 4 vCPU and 16 GB memory values.

- Compute Savings Plans rate for m5.xlarge in the US East (Ohio) for one-year term and No Upfront is 0.141 USD

- Hours in the commitment: 365 days * 24 hours * 1 year = 8760.0000 hours

- Total Commitment: 0.141 USD * 8760 hours = 1235.1600 USD

- Upfront: No Upfront (0% of 1235.16) = 0.0000 USD

- Hourly cost for Compute Savings Plans = (Total Commitment – Upfront cost)/Hours in the term: (1235.16 – 0.00)/8760 = 0.1410 USD

- Normalized Compute Savings Plans monthly price: (0.000000 USD / 12 months) + (0.141000 USD x 730 hours in a month) = 102.930000 USD

The Fargate monthly price for the same configuration (Always Active):

- (4 vCPU  x 0.04048 USD per hour x  24 hours x 30 days) + 16 GB x 0.00445 USD per hour x 24 hours x 30 days = $167.78

It is important to note that Fargate pricing starts decreasing with the increase of resource idle time.

## AWS EKS Costs – Standalone with no Fargate Service
While AWS ECS is free, and you only pay for the EC2 instances used, [Amazon EKS](https://www.clickittech.com/aws/amazon-ecs-vs-eks/?utm_source=devto&utm_medium=referral#whatiseks) comes with a charge of $0.10 per hour per EKS cluster you create. There are additional charges to compute and storage resources used by these clusters. It means you’ll incur an additional monthly fee of $74 on each cluster compared to ECS. 

However, EKS is a fully-managed Kubernetes service, and the ease with which you can manage container clusters outweighs the price difference. For instance, a single EKS cluster enables you to run multiple apps. 

## Fargate vs ECS vs EKS: Pricing Comparison
Here is a comparison of ECS with EC2 launch type and Fargate launch type:



![Fargate vs ECS vs EKS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bbzpzpfqc8z28518tm3y.png)



When comparing Fargate pricing with that of ECS or EKS, Fargate costs more for vCPU and GB resources. However, AWS meters RAM and CPU independently and doesn’t count the unused cluster capacity. So, the cluster reservation rate is making the difference here in terms of costs. 


![Fargate vs ECS/EKS costs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8p4pywlm4knbmgk63bf.png)

## Conclusion
If your ECS cluster utilization is 100%, you’ll save 20%-30% on costs compared to Fargate. Anything less than 80% will cost you more than Fargate pricing. However, consider the infrastructure management tasks such as configuring, running, patching, and securing hosted VMs. Autoscaling resources at the cluster and container level is another headache. 

With the right-sized Fargate configuration, you gain on costs and complexities of infrastructure management.

---
**Original post on [ClickIT](https://www.clickittech.com/?utm_source=devto&utm_medium=referral):** https://www.clickittech.com/devops/fargate-pricing/?utm_source=devto&utm_medium=referral

**For more AWS Services Pricing on specific projects, you can check out our content or request more information here:** https://www.clickittech.com/contact/?utm_source=devto&utm_medium=referral