Understanding task placement strategies matters when you’re running ECS on EC2 instances (not Fargate) and want control over how tasks get distributed across your cluster. Picking the wrong strategy can lead to uneven resource usage or poor availability.

Amazon ECS supports the following task placement strategies:

binpack – Place tasks based on the least available amount of CPU or memory. This minimizes the number of instances in use.

random – Place tasks randomly.

spread – Place tasks evenly based on the specified value. Accepted values are attribute key-value pairs, instanceId, or host.

(See my deeper write-up on AWS.)

For production workloads, I typically use spread by availability zone for high availability, combined with binpack by memory as a secondary strategy to keep costs down. You can chain multiple strategies together in your task definition. The random strategy is mostly useful for testing or when you genuinely don’t care about placement.