Lesson 5 of 6 Amazon ECS, EKS and Fargate

Scaling Containers and Their Capacity

This lesson explains how container platforms scale at two levels: the number of tasks or pods, and the capacity those tasks run on.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how tasks and their capacity scale together.
  • Explain how capacity provider strategies split tasks.
  • Describe how batch and scheduled containers run.

Two layers of scaling

Container platforms scale at two layers, and both must work for the application to grow. The first layer is the number of tasks or pods running the application. In ECS, Service Auto Scaling adjusts a service's task count with target tracking on CPU, memory or ALB requests, or on custom metrics such as the depth of an SQS queue. In EKS, the Horizontal Pod Autoscaler adjusts the number of pod replicas.

The second layer is the capacity the tasks run on. With Fargate this is automatic. On EC2, ECS capacity providers scale an Auto Scaling group to fit the tasks, or mix Fargate and Fargate Spot in chosen proportions. In EKS, Karpenter or the Cluster Autoscaler adds nodes when pods cannot be placed, or EKS Auto Mode manages nodes entirely. The following table summarises the mechanisms.

ECS
Tasks or podsService Auto Scaling: target tracking on CPU, memory, ALB requests or custom metrics such as SQS depth
CapacityCapacity providers: scale an Auto Scaling group, or mix Fargate and Fargate Spot
Kubernetes on EKS
Tasks or podsHorizontal Pod Autoscaler
CapacityKarpenter, Cluster Autoscaler or Auto Mode

The following diagram shows the two layers and the mechanisms for each.

Container platforms scale at two layers. The application layer changes the number of tasks or pods: ECS Service Auto Scaling or the Kubernetes Horizontal Pod Autoscaler. The capacity layer adds the compute they run on: automatic with Fargate, ECS capacity providers on EC2, or Karpenter, the Cluster Autoscaler or EKS Auto Mode for EKS nodes.
Scaling tasks without scaling capacity leaves new tasks waiting for somewhere to run.

Capacity provider strategies

A strategy splits tasks across providers with a base and weights, for example a base of two tasks on Fargate for reliability and the rest weighted 1:3 between Fargate and Fargate Spot to cut cost. On EC2, managed scaling grows the Auto Scaling group as tasks need room.

Scenario questions

Scaling containers

Exam skills 3.2.1 · 4.2.2

Choose the container scaling approach for each requirement.

Log in to try this activity Interactive activities are free with an account.

Batch and scheduled containers

Not every container serves requests. Batch jobs that must be queued, prioritised and retried run on AWS Batch, which manages job queues and launches the necessary capacity on ECS, EKS or Fargate, including Spot, and scales it down when the queue is empty. Scheduled tasks, such as a nightly report, run as ECS tasks started by EventBridge Scheduler, so no instance has to wait idle for the scheduled time. The following table summarises the choice.

NeedUse
Batch jobs with queues and prioritiesAWS Batch on ECS, EKS or Fargate
Scheduled tasksECS tasks started by EventBridge Scheduler
Worked example

Scaling queue workers on Fargate

An ECS service processes jobs from an SQS queue. The backlog varies from zero to 50,000 messages, and the team wants to cut cost.

SettingChoice
Task scaling metricBacklog per task, from queue depth divided by running tasks
Minimum tasksOne, so work starts immediately
Capacity provider strategyBase of one task on Fargate, the rest weighted towards Fargate Spot

Because the jobs can be retried, interruptions of Spot tasks cost nothing but time, and the queue keeps the work safe.

Check yourself

What are the two layers of scaling for ECS on EC2?

Show answer

Service auto scaling changes the number of tasks, and a capacity provider with managed scaling changes the number of EC2 instances to fit them.

Exam Tips

Remember for the exam

  • To scale ECS tasks on queue depth, use Service Auto Scaling with a custom metric.
  • To mix Fargate and Fargate Spot for cost, use a capacity provider strategy.
  • To scale Kubernetes nodes quickly and efficiently, use Karpenter.
  • For batch container jobs with queues, use AWS Batch.