# AWS Fargate

***

#### What is Fargate?

Fargate is Serverless Compute for Containers.

<a class="button secondary"></a>

To understand Fargate, you have to understand the problem with standard containers (ECS/EKS) on EC2:

* The "Old" Way (EC2 Launch Type): You want to run a Docker container. First, you have to provision a cluster of virtual machines (EC2s). You have to update their OS, patch them, and worry about "bin packing" (fitting your containers onto the servers efficiently).
* The Fargate Way: You just tell AWS: *"Run this Docker container. It needs 2 vCPUs and 4 GB of RAM."* AWS finds a place to run it instantly. You never see the server, you don't manage the OS, and you only pay for the resources that specific container uses.

  <a class="button secondary"></a>

The Analogy:

* EC2 is like renting a house to throw a party (you have to clean up, manage space, and pay rent even if no one shows up).
* Fargate is like booking a table at a restaurant (you show up, eat, pay only for your meal, and leave. The restaurant manages the building).

#### How it fits with ECS & EKS

This is the most confusing part for beginners: Fargate is not a replacement for ECS or EKS. It is an *option* you choose when using them.

* ECS on EC2: You manage the fleet of servers. Cheaper for massive scale, but more work.
* ECS on Fargate: You manage nothing. Slightly more expensive per hour, but saves massive amounts of engineering time.

#### Equivalents

| **Cloud** | **Equivalent Service**        | **Why?**                                                                                                                               |
| --------- | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| GCP       | Cloud Run (or GKE Autopilot)  | Cloud Run is Google's "Serverless Container" service. Like Fargate, you give it a container, and it runs it without you seeing the VM. |
| Azure     | Azure Container Apps (or ACI) | Azure Container Instances (ACI) was the pioneer here, allowing you to run containers without managing VMs.                             |

Data Engineer Note:

You will often use Fargate for sporadic data tasks. For example, if you have a Python script that scrapes a website once a day, you don't want an EC2 server running 24/7. You package the script in a container and run it on ECS Fargate. It spins up, runs the script, shuts down, and costs you pennies.

***
