How the ECS Scheduler Places & Replaces Tasks

~10 min read

What actually happens inside ECS when a service's desired count changes or a task fails.

The ECS scheduler continuously compares a service's desired task count against its actual running task count and takes action to reconcile any difference. On the EC2 launch type, placement strategies (spread, binpack, random) determine which instance a new task lands on — 'spread' across Availability Zones is the default and most common choice for resilience, ensuring an AZ outage doesn't take down every task at once. On Fargate, AWS handles placement transparently since there's no visible instance layer to choose between. When a task fails a health check (either the ECS container health check or, more commonly, the load balancer target group's health check), ECS deregisters it from the target group, stops it, and launches a replacement — this entire loop typically completes in well under a minute, which is why ECS services can absorb individual task failures without visible downtime as long as desired count stays above the traffic-serving minimum.

💬 Deep Dive with AI

Key points

  • •The scheduler continuously reconciles actual task count toward desired task count
  • •Placement strategy 'spread' across AZs is the default resilience pattern on EC2 launch type
  • •A failed health check triggers deregistration + termination + replacement, usually within a minute
  • •Desired count should always account for at least N+1 capacity so one task failure never drops below traffic-serving minimum