Ace Cloud Interviews
🐳

AWS Containers

Fargate

Serverless compute engine for containers - no EC2 instances to manage

AWS Fargate is a serverless compute engine for containers that works with both ECS and EKS, eliminating the need to provision, configure, or scale EC2 instances. You define CPU and memory requirements per task or pod, and Fargate allocates compute resources automatically. Fargate is ideal for variable workloads, batch jobs, and teams who want to focus on application code rather than infrastructure management.

How Fargate Executes Containers

Fargate uses a micro-VM architecture. Each task (ECS) or pod (EKS) runs in an isolated Firecracker micro-VM with dedicated vCPU and memory. This provides stronger isolation than shared EC2 nodes where containers share the kernel.

AspectTraditional EC2 ContainersFargate
IsolationShared EC2 kernel - container-level isolationDedicated micro-VM per task/pod - VM-level isolation
ProvisioningProvision EC2 instances before deployingNo instances to provision - define CPU/memory in task
VisibilityFull access to host OS, logs, diskNo host access - all through CloudWatch Logs and ECS APIs
ScalingScale instances + tasks separatelyScale tasks only - no node scaling needed
Startup timeNear-instant if instance is running10-30 seconds for new task - micro-VM boot time
Multi-tenancyMultiple customers may share a hostSingle tenant per micro-VM - stricter compliance
💡

Fargate's Firecracker micro-VM isolation is the reason it qualifies for compliance frameworks (PCI-DSS, HIPAA) that require strong tenant isolation. Each task is completely isolated at the hypervisor level.

CPU and Memory Sizing Combinations

Fargate does not let you pick arbitrary CPU and memory values. You must use one of the supported combinations. Choosing the wrong size is a common cost and performance issue.

vCPUAllowed Memory RangeGranularity
0.25512MB - 2GB512MB increments
0.51GB - 4GB1GB increments
12GB - 8GB1GB increments
24GB - 16GB1GB increments
48GB - 30GB1GB increments
816GB - 60GB4GB increments
1632GB - 120GB8GB increments

Ephemeral storage is 20GB by default, expandable to 200GB for an additional cost. Fargate also supports EFS for shared persistent storage.

⚠️

Fargate charges for the vCPU and memory you configure, not what you actually use. A task configured as 4 vCPU/8GB that only uses 0.5 vCPU/1GB still pays for 4 vCPU/8GB. Right-size your tasks using CloudWatch Container Insights metrics.

Fargate Pricing vs EC2 - When Each Wins

Fargate pricing is per-second for vCPU and memory. The break-even point with EC2 depends on utilization. Below ~20-30% average CPU utilization, Fargate is often cheaper; above that, EC2 reserved instances win.

Pricing ComponentRate (us-east-1)Notes
vCPU$0.04048/vCPU/hourCharged per second, 1-minute minimum
Memory$0.004445/GB/hourCharged per second, 1-minute minimum
Fargate Spot vCPU~$0.01220/vCPU/hour (~70% discount)Can be interrupted - use for fault-tolerant workloads
Fargate Spot memory~$0.00133/GB/hourSame discount as vCPU
Ephemeral storage (>20GB)$0.000111/GB/hourFirst 20GB free

Cost comparison example: 1 vCPU, 2GB Fargate task running 24/7 for 30 days = (~$0.04048 + 2 x $0.004445) x 720 hours = ~$35.63/month. Equivalent t3.small (2 vCPU, 2GB) On-Demand = $15.18/month, 1-year Reserved = $9.49/month.

ScenarioWinnerReason
Spiky web API (20% avg utilization)FargateNo idle capacity cost
Always-on microservice at 80% CPUEC2 ReservedFargate 3x more expensive at high utilization
Nightly batch job (2 hours/day)FargatePay only for 2 hours, no idle instance cost
High throughput data processingEC2 (c5.xlarge)Better price-per-vCPU and network throughput
Dev/test environmentsFargateScale to zero, no overnight costs
Compliance-sensitive multi-tenantFargateVM-level isolation without managing hosts

Networking, Security Groups, and VPC Design

Every Fargate task runs in awsvpc networking mode and gets its own ENI injected into your VPC. This means every task has a unique private IP and can have its own security group.

Fargate tasks in private subnets need either a NAT Gateway or VPC endpoints to reach AWS services and ECR.

Connectivity NeedSolutionCost
Pull from ECRECR VPC endpoint (PrivateLink)VPC endpoint + data processing charges
Write CloudWatch LogsCloudWatch Logs VPC endpointVPC endpoint charges
Access internetNAT Gateway in public subnet$0.045/hr + data charges
Access S3S3 Gateway endpointFree
Access Secrets ManagerSecrets Manager VPC endpointVPC endpoint charges
💡

For production Fargate in private subnets, the minimum VPC endpoints needed are: ecr.api, ecr.dkr, s3 (gateway), and logs. Without these, tasks fail to pull images or write logs. S3 is needed because ECR stores image layers in S3 internally.

bash
# Minimal ECS Fargate task in private subnet (via CDK-like CloudFormation)
# Security group - inbound from ALB only, outbound to VPC endpoints
TaskSecurityGroup:
  Type: AWS::EC2::SecurityGroup
  Properties:
    GroupDescription: Fargate task SG
    SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: 8080
        ToPort: 8080
        SourceSecurityGroupId: !Ref ALBSecurityGroup
    SecurityGroupEgress:
      - IpProtocol: "-1"
        CidrIp: 10.0.0.0/16  # VPC CIDR - reaches VPC endpoints and RDS

Observability: Logs, Metrics, and Debugging Without SSH

With Fargate, you cannot SSH into the host. All observability must be configured in advance through logging, metrics, and the ECS Exec feature.

Observability ToolWhat It ProvidesHow to Configure
CloudWatch LogsContainer stdout/stderrawslogs log driver in task definition
Container InsightsCPU, memory, network, disk per taskEnable on ECS cluster
ECS ExecInteractive shell into running containerenableExecuteCommand=true on service
AWS X-RayDistributed tracingAdd X-Ray sidecar container to task definition
FireLensRoute logs to external destinations (Splunk, Datadog)Add Fluent Bit sidecar as log router
bash
# ECS Exec - interactive access to running Fargate task (no SSH needed)
# 1. Enable on service
aws ecs update-service \
  --cluster my-cluster \
  --service my-service \
  --enable-execute-command

# 2. Start interactive session
aws ecs execute-command \
  --cluster my-cluster \
  --task arn:aws:ecs:us-east-1:123:task/abc123 \
  --container my-app \
  --interactive \
  --command "/bin/bash"

# Requires: SSM agent in container, correct IAM permissions on task role
⚠️

ECS Exec requires the SSM Agent to be running inside the container. Official AWS images (Amazon Linux 2, ECS-optimized) include it. Custom minimal images (Alpine-based) do not. Add the SSM agent installation to your Dockerfile if using ECS Exec on custom images.

🎯

Interview Focus Points

  • 1When would you choose Fargate over EC2 launch type for ECS - what is the cost break-even point?
  • 2How does Fargate networking work - why does each task need its own ENI and what are the implications?
  • 3What VPC endpoints are required for Fargate tasks in private subnets and why?
  • 4How does Fargate Spot work and what types of workloads are suitable for it?
  • 5How do you debug a Fargate container when you cannot SSH into the host?
  • 6Explain the Firecracker micro-VM used by Fargate - what security benefits does it provide?
  • 7How would you right-size a Fargate task - what metrics would you look at?
  • 8What are the limitations of Fargate compared to EC2 launch type (DaemonSets, GPU, storage, etc.)?
  • 9How does Fargate handle persistent storage - what are the options and trade-offs?