This chapter covers AWS Fargate task placement strategies and availability, focusing on how tasks are scheduled onto underlying infrastructure. For the SAA-C03 exam, understanding these concepts is crucial for designing resilient, highly available containerized applications. Approximately 10-15% of exam questions touch on ECS and Fargate, with task placement and availability being a key subdomain under Resilient Architectures (Objective 2.1).
Jump to a section
Imagine an apartment building with no individual mailboxes — all packages arrive at a central mailroom. The mailroom has a limited number of lockers (available IP addresses). When a tenant (task) moves in, they request a locker. The mailroom manager (AWS Fargate) assigns a specific locker from the pool and records it in a log. If the tenant leaves (task stops), the locker is freed for the next tenant. If the building has more tenants than lockers, some must wait or be told there's no space (insufficient capacity). The manager can also decide to place tenants in lockers on different floors (Availability Zones) to ensure that if one floor's power fails, not all tenants lose service. This is task placement — deciding which locker (underlying infrastructure) gets which tenant, based on availability and spreading rules. Without this system, tenants would fight over lockers, or all would be on one floor, risking total outage.
What is ECS Fargate Task Placement?
Amazon ECS (Elastic Container Service) with Fargate launch type allows you to run containers without managing servers. However, even with Fargate, AWS must decide where to place each task — which underlying compute resources (e.g., CPU, memory) are allocated. Task placement is the process by which the ECS scheduler determines the infrastructure (host) for a task. For Fargate, this is abstracted, but the scheduler still applies placement constraints and strategies to meet availability and capacity requirements.
Why Task Placement Matters for Availability
When you run multiple tasks of a service, you want them distributed across Availability Zones (AZs) to tolerate an AZ failure. Without proper placement, all tasks could end up in one AZ, creating a single point of failure. Task placement strategies control this distribution.
Task Placement Strategies
ECS supports three types of task placement strategies:
Binpack – Places tasks based on the least available amount of CPU or memory. This minimizes the number of hosts used, which can be cost-effective but may reduce availability if too many tasks are on one host.
Random – Places tasks randomly across hosts. Simple but not optimal for availability.
Spread – Distributes tasks evenly across specified values (e.g., AZ, host). This is the key strategy for high availability.
In addition to strategies, you can define placement constraints using Amazon ECS attributes or custom attributes.
How Fargate Handles Placement
Fargate abstracts the host, but the ECS scheduler still uses placement strategies to decide which AZ and which underlying infrastructure (the Fargate platform) gets the task. The scheduler considers:
Availability Zone – You can specify subnets in multiple AZs. The scheduler will place tasks across those subnets based on the strategy.
CPU and Memory – The task definition specifies CPU and memory. The scheduler checks if the required resources are available in the Fargate platform (which has finite capacity per AZ).
Placement Constraints – You can use distinctInstance to place each task on a different host (for Fargate, this is per AZ, since hosts are abstracted).
Default Values and Timers
Default strategy: If no strategy is specified, ECS uses spread across AZs by default for services (but not for standalone tasks). For tasks, the default is random.
Placement engine: The scheduler uses a two-phase process: first, it identifies valid hosts (or AZs for Fargate) that meet constraints; second, it selects a host based on the strategy.
Service scheduler: For services, the scheduler continuously monitors desired vs. running count and rebalances tasks if needed.
Configuration and Verification
You can set placement strategy in the ECS service definition using the AWS CLI, SDK, or console. Example CLI command to create a service with spread strategy across AZs:
aws ecs create-service \
--cluster my-cluster \
--service-name my-service \
--task-definition my-task:1 \
--desired-count 3 \
--network-configuration "awsvpcConfiguration={subnets=[subnet-abc,subnet-def],securityGroups=[sg-123]}" \
--placement-strategy type=spread,field=attribute:ecs.availability-zoneTo verify placement, use:
aws ecs describe-tasks --cluster my-cluster --tasks arn:aws:ecs:...This returns the availabilityZone for each task.
Interaction with Related Technologies
Auto Scaling: ECS Service Auto Scaling can adjust desired count based on metrics. Placement strategy affects how new tasks are distributed.
Load Balancer: An Application Load Balancer (ALB) distributes traffic across tasks in different AZs. If tasks are not spread, the ALB may send traffic to a single AZ, causing imbalance.
CloudWatch: You can monitor task distribution using custom metrics.
Step-by-Step Placement Process
User creates or updates a service with a placement strategy.
ECS scheduler retrieves the list of available Fargate infrastructure in each AZ (based on subnets specified).
Scheduler filters out AZs that cannot satisfy task resource requirements (CPU/memory).
For spread strategy, the scheduler calculates the current distribution of tasks per AZ.
Scheduler selects the AZ with the fewest tasks (or based on other spread fields).
Task is launched in the selected AZ using the Fargate platform.
If no AZ can accommodate (e.g., insufficient capacity), the task remains pending until capacity is available.
Important Exam Values
Maximum tasks per service: 1,000 (soft limit).
Placement strategy types: binpack, random, spread.
Spread fields: attribute:ecs.availability-zone and instanceId (for EC2; for Fargate, only AZ is relevant).
Constraints: distinctInstance and memberOf (using expressions).
Availability and Resiliency
To achieve high availability:
Use at least two AZs.
Use spread strategy with attribute:ecs.availability-zone.
Set desiredCount to at least 2.
Use an ALB in front to distribute traffic across AZs.
If you use binpack, tasks may be placed in fewer AZs, reducing resilience. The exam often tests the trade-off between cost (binpack) and availability (spread).
Common Pitfalls
Forgetting to specify subnets in multiple AZs. If you only specify one subnet, all tasks go to one AZ regardless of strategy.
Using random strategy thinking it spreads evenly – it does not guarantee even distribution.
Assuming distinctInstance works for Fargate: In Fargate, distinctInstance is not supported because there is no instance concept. Instead, use spread across AZ.
Code Example: Service with Spread Strategy
{
"serviceName": "web-app",
"taskDefinition": "web-app:1",
"desiredCount": 4,
"networkConfiguration": {
"awsvpcConfiguration": {
"subnets": ["subnet-a", "subnet-b", "subnet-c"],
"securityGroups": ["sg-123"]
}
},
"placementStrategy": [
{
"type": "spread",
"field": "attribute:ecs.availability-zone"
}
]
}This ensures tasks are spread across three AZs as evenly as possible.
Define Service with Placement Strategy
You create an ECS service with a task definition, desired count, and network configuration. You specify one or more placement strategies. For high availability, you use `spread` across `attribute:ecs.availability-zone`. This tells the scheduler to distribute tasks evenly across the AZs that correspond to the subnets you provided. You must list subnets from at least two different AZs for spreading to work.
Scheduler Evaluates Available Capacity
The ECS scheduler queries the Fargate platform to determine the available capacity in each AZ. Fargate has a finite pool of resources per AZ (e.g., CPU and memory). If an AZ has insufficient capacity for the task's resource requirements, it is excluded from consideration. This step ensures that only AZs that can actually run the task are candidates. If no AZ has capacity, the task stays in `PENDING` state.
Apply Constraints and Filter AZs
If you have defined placement constraints (e.g., `memberOf` expressions), the scheduler applies them now. For Fargate, constraints like `distinctInstance` are not applicable. The constraint `attribute:ecs.availability-zone` is implicit. The result is a list of valid AZs that meet both resource and constraint requirements.
Calculate Spread Distribution
For `spread` strategy, the scheduler examines the current task distribution across the valid AZs. It counts how many tasks are already running in each AZ. The goal is to place the new task in the AZ with the fewest tasks. If there is a tie, the scheduler picks one arbitrarily (AWS does not specify the tiebreaker, but it is likely random). This step ensures even distribution over time.
Launch Task in Selected AZ
The scheduler instructs the Fargate platform to launch the task in the chosen AZ. Fargate allocates the required CPU and memory from its pool. The task receives an IP address from the subnet associated with that AZ. The task enters `RUNNING` state. If the launch fails (e.g., capacity suddenly exhausted), the scheduler retries with a different AZ or re-evaluates.
Scenario 1: E-Commerce Microservices
A large e-commerce platform runs its product catalog, cart, and checkout as separate ECS services on Fargate. They operate in three AZs (us-east-1a, 1b, 1c). Each service has a desired count of 6 tasks. They use spread across AZs to ensure that if one AZ fails, each service still has 4 tasks running in the other two AZs. This is configured with the placement strategy shown earlier. The ALB is configured with cross-zone load balancing enabled to distribute traffic evenly across all healthy tasks. Performance is monitored via CloudWatch metrics for CPU and memory; if utilization exceeds 80%, Service Auto Scaling adds tasks, which are spread automatically.
Scenario 2: Batch Processing Workload
A financial analytics company runs batch jobs on Fargate. They have a single service that processes large datasets. They want to minimize cost, so they use binpack strategy with field: memory to pack tasks onto as few hosts as possible. However, they still run in two AZs for basic availability. They set desiredCount to 2, one per AZ, but binpack might place both in the same AZ if memory is more available there. To force distribution, they use a custom attribute per AZ and a memberOf constraint. This scenario shows that binpack is not ideal for availability; the exam tests this trade-off.
Common Misconfiguration
A developer creates a service with subnets from only one AZ but uses spread strategy across AZs. All tasks end up in that single AZ because there is no other AZ to spread to. The service appears healthy until that AZ fails, causing complete outage. The exam loves this trap: the strategy does not override the subnet list; it only spreads across the AZs that are available via the subnets. Always ensure subnets span multiple AZs.
What SAA-C03 Tests
Objective 2.1: Design highly available and/or fault-tolerant architectures. The exam tests your ability to choose the correct placement strategy to achieve high availability. Key points:
Spread vs. Binpack: Know when to use each. Spread for availability, binpack for cost.
Placement Constraints: Understand distinctInstance (for EC2 only) and memberOf (for custom attributes).
AZ Distribution: You must specify subnets in multiple AZs; otherwise, spreading does nothing.
Fargate vs. EC2: For Fargate, you cannot use instance-level constraints; only AZ-level spreading is supported.
Common Wrong Answers
"Use random strategy for high availability" – Random does not guarantee even distribution; it could place all tasks in one AZ. Candidates pick this because "random" sounds like it spreads, but it doesn't.
"Use distinctInstance constraint for Fargate" – This is only for EC2 launch type. Candidates confuse the two launch types.
"Binpack is best for availability because it leaves more hosts free" – Binpack concentrates tasks, reducing availability.
"Specify spread across instanceId for Fargate" – InstanceId is not an attribute in Fargate; the correct field is attribute:ecs.availability-zone.
Specific Numbers and Terms
Desired count: At least 2 for availability.
Subnets: Minimum 2 from different AZs.
Strategy types: binpack, random, spread.
Field for AZ: attribute:ecs.availability-zone.
Constraint: "type": "distinctInstance" (EC2 only).
Edge Cases
Tasks in PENDING state: Often due to insufficient capacity in all AZs. The exam may ask why tasks are not running; answer: no capacity in the AZs defined by subnets.
Service Auto Scaling: If you scale in, tasks are terminated based on the same placement strategy, which may cause imbalance temporarily.
How to Eliminate Wrong Answers
If the question asks for "high availability" and the answer mentions binpack, eliminate it.
If the answer mentions distinctInstance for Fargate, eliminate it.
If the answer suggests using one subnet, eliminate it.
Look for answers that explicitly mention multiple AZs and spread strategy.
Use 'spread' across 'attribute:ecs.availability-zone' for high availability.
Always specify subnets from at least two different AZs for multi-AZ distribution.
Binpack minimizes cost but reduces availability; random does not guarantee even spread.
DistinctInstance constraint is only for EC2 launch type, not Fargate.
For Fargate, placement constraints are limited; you cannot use instance-level constraints.
If tasks are stuck in PENDING, check capacity in the AZs defined by subnets.
Service Auto Scaling respects placement strategy; new tasks follow the same strategy.
These come up on the exam all the time. Here's how to tell them apart.
Spread Placement Strategy
Distributes tasks evenly across specified fields (e.g., AZ)
Maximizes availability by reducing impact of a single AZ failure
Uses more hosts (or AZs) potentially increasing cost
Recommended for production workloads requiring high availability
Field: attribute:ecs.availability-zone
Binpack Placement Strategy
Places tasks based on least available CPU or memory to minimize hosts
Reduces availability as tasks are concentrated on fewer hosts
More cost-effective as it uses fewer underlying resources
Suitable for batch jobs or non-critical workloads where cost is priority
Field: attribute:ecs.cpu or attribute:ecs.memory
Mistake
Fargate tasks are automatically spread across AZs without any configuration.
Correct
No, you must specify subnets in multiple AZs and use a spread strategy. Without subnets from multiple AZs, all tasks go to one AZ. Without a spread strategy, tasks may be placed randomly or binned.
Mistake
Using 'random' placement strategy ensures tasks are evenly distributed across AZs.
Correct
Random does not guarantee even distribution. It may place all tasks in the same AZ by chance. For even distribution, use 'spread' across 'attribute:ecs.availability-zone'.
Mistake
The 'distinctInstance' placement constraint can be used with Fargate to place each task on a different host.
Correct
Fargate abstracts the host; 'distinctInstance' is only valid for EC2 launch type. For Fargate, use spread across AZs to achieve similar isolation at the AZ level.
Mistake
Binpack placement strategy is best for high availability because it conserves resources.
Correct
Binpack minimizes the number of hosts used, which reduces availability because a single host failure affects more tasks. For high availability, use spread.
Mistake
You can place tasks across AZs by specifying multiple subnets in the same AZ.
Correct
Subnets are tied to a single AZ. To distribute across AZs, you must specify subnets from different AZs. Listing multiple subnets in the same AZ does not spread tasks across AZs.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
You must specify subnets that reside in different AZs when creating the service. Then set a placement strategy of type 'spread' with field 'attribute:ecs.availability-zone'. This tells the scheduler to place tasks evenly across the AZs represented by those subnets. Without multiple subnets, all tasks go to one AZ.
Spread distributes tasks evenly across a specified field (e.g., AZ) to maximize availability. Binpack places tasks on the least utilized hosts to minimize the number of hosts used, which reduces cost but can lower availability. Choose spread for production, binpack for cost-sensitive non-critical workloads.
No. 'distinctInstance' is only supported for the EC2 launch type, where each task is placed on a different EC2 instance. For Fargate, the underlying host is abstracted, so this constraint is not applicable. Instead, use spread across AZs for similar isolation.
This usually means there is insufficient capacity in the AZs you specified. Check if the subnets are in AZs that have available Fargate resources for the required CPU and memory. Also ensure that the VPC has enough IP addresses in those subnets. You can also add more subnets from different AZs to increase capacity.
Yes, when Auto Scaling increases or decreases the desired count, the new tasks are placed according to the service's placement strategy. For example, if using spread across AZs, new tasks will be placed in the AZ with the fewest tasks to maintain balance.
If you do not specify a placement strategy for a service, ECS uses a default strategy of 'spread' across AZs. For standalone tasks (not services), the default is 'random'. It's best practice to explicitly set the strategy to avoid surprises.
Yes, but only the 'memberOf' constraint with attribute expressions is supported. For example, you can use 'attribute:ecs.availability-zone in [us-east-1a, us-east-1b]' to restrict to specific AZs. The 'distinctInstance' constraint is not supported.
You've just covered ECS Fargate: Task Placement and Availability — now see how well it sticks with free SAA-C03 practice questions. Full explanations included, no account needed.
Done with this chapter?