Nov 23, 20265 min read

ECS Deployment Circuit Breaker and Automatic Rollback

How the ECS deployment circuit breaker detects a failed rolling deployment, how its failure threshold is calculated and tuned, how CloudWatch alarm rollbacks catch bad releases that pass health checks, and how to get alerted when a rollback happens.

Illustration for ECS Deployment Circuit Breaker and Automatic Rollback

A rolling ECS deployment with a broken image used to retry forever: new tasks crash, ECS starts more, and the service sits half-deployed for hours while the old tasks keep serving traffic and nobody gets told.

The deployment circuit breaker stops that loop, marks the deployment as failed and can roll back on its own, and it takes one setting plus a little tuning to make it fit the service.

At a glance

Circuit breakerCloudWatch alarm rollback
DetectsTasks that never reach RUNNING or fail health checksAny metric you alarm on, such as 5xx rate or latency
Catches healthy-but-wrong releasesNoYes
Rollback targetLast deployment in COMPLETED stateSame
ConfigurationdeploymentCircuitBreakeralarms in deploymentConfiguration
Works withRolling update (ECS) controllerRolling update and blue/green
Event on failureSERVICE_DEPLOYMENT_FAILEDSERVICE_DEPLOYMENT_FAILED

Turn it on

aws ecs update-service \ --cluster prod \ --service orders \ --deployment-configuration "deploymentCircuitBreaker={enable=true,rollback=true}"

The circuit breaker documentation describes the evaluation in two stages. First, the scheduler watches whether new tasks reach RUNNING, counting tasks that do not toward the failure threshold. Once at least one task is running, it checks load balancer, Cloud Map and container health checks, and counts tasks replaced for failing them. The deployment succeeds when tasks are running and healthy, and fails when the count reaches the threshold.

On failure with rollback=true, ECS starts a new deployment of the most recent one in the COMPLETED state. If there is none, for example because a rollback is itself still in progress, the deployment stalls without launching tasks.

Tune the threshold

By default the threshold is BOUNDED_PERCENT with a value of 50: half the desired count, rounded up and clamped to between 3 and 200. A service with one task needs 3 failures, one with 25 tasks needs 13, and one with 800 still stops at 200. Two settings change that:

aws ecs update-service \ --cluster prod \ --service orders \ --deployment-configuration "deploymentCircuitBreaker={enable=true,rollback=true,resetOnHealthyTask=false,thresholdConfiguration={type=COUNT,value=3}}"

COUNT fixes the number of tolerated failures regardless of size, which gives faster rollbacks for large services, and UNBOUNDED_PERCENT removes the 200 cap for very large ones. resetOnHealthyTask defaults to true, so the count resets whenever a task becomes healthy and only consecutive failures count, which tolerates a flaky start. Setting it to false accumulates every failure in the deployment and catches an image that crashes one task in three.

Catch releases that start but misbehave

A release that boots, passes /health and then returns 500s on half the endpoints sails through the circuit breaker. Deployment alarms cover that case: list CloudWatch alarms in deploymentConfiguration.alarms with rollback=true, and ECS keeps the deployment in progress for a bake time after the tasks are steady, rolling back if any alarm goes into ALARM. Alarm on the target group's HTTPCode_Target_5XX_Count or p99 latency for the service, with thresholds tight enough to catch a bad release and loose enough to ignore normal noise.

Get told when it happens

A silent rollback leaves a merged change that never shipped. Create an EventBridge rule for ECS service deployment state change events with eventName SERVICE_DEPLOYMENT_FAILED, which the docs recommend, and send it to a chat channel or on-call tool, then use describe-services and the rolloutStateReason field to see why.

Best fit: every rolling-update ECS service, with the circuit breaker for startup failures and alarms for errors after startup.

Fewer failed deploys with Encore

Encore

Encore brings infrastructure from code and deploys services to Fargate or EKS in your AWS account, and the AWS infrastructure docs describe Fargate services set up with rolling updates, load balancer health checks and health check grace periods so new tasks get time to start before they receive traffic. The cheapest rollback is the one that never happens, so most of the gain comes earlier: the app is compiled and its infrastructure declarations validated before deploy, and each pull request can get a preview environment to exercise the change in the cloud.

Startup failures are the circuit breaker's main trigger, and a service that checks its own dependencies when it initializes turns a vague crash loop into a clear error. This pricing service loads and validates its rules once, in initService, instead of failing on every request later:

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

// pricing/pricing.go package pricing import ( "context" "encoding/json" "fmt" "encore.dev/beta/errs" ) var secrets struct { // JSON map of plan name to monthly price in cents, set per environment. PlanPrices string } //encore:service type Service struct { prices map[string]int64 } func initService() (*Service, error) { var prices map[string]int64 if err := json.Unmarshal([]byte(secrets.PlanPrices), &prices); err != nil { return nil, fmt.Errorf("PlanPrices is not valid JSON: %w", err) } if len(prices) == 0 { return nil, fmt.Errorf("PlanPrices is empty") } return &Service{prices: prices}, nil } type Quote struct { Plan string `json:"plan"` PriceCents int64 `json:"price_cents"` } //encore:api public method=GET path=/pricing/:plan func (s *Service) Get(ctx context.Context, plan string) (*Quote, error) { p, ok := s.prices[plan] if !ok { return nil, &errs.Error{Code: errs.NotFound, Message: "unknown plan"} } return &Quote{Plan: plan, PriceCents: p}, nil }

The service structs docs describe initService as the place to set up dependencies when the service starts, and the secrets docs cover setting PlanPrices per environment, with values kept out of the repository. A malformed value shows up as one clear initialization error in encore run or the preview environment, instead of as a stream of failing requests after a production deploy.

When an AI coding agent changes configuration parsing or adds a dependency, running the app locally and opening a pull request with a preview environment gives it two places to find the break before ECS ever has to roll anything back.

Best fit: teams on Fargate who want failed releases caught before production and production rollouts that replace tasks gradually.

Frequently asked questions

What is the ECS deployment circuit breaker?

It is a setting on ECS services that use rolling updates which marks a deployment as FAILED when too many new tasks fail to start or fail health checks. With rollback enabled, ECS then redeploys the last deployment that reached the COMPLETED state.

How many failed tasks trigger the ECS circuit breaker?

By default the threshold is 50 percent of the desired count, rounded up and clamped between 3 and 200, so a service with 25 tasks fails after 13 failures. You can change it with thresholdConfiguration, using a fixed COUNT or an unbounded percentage.

Does the ECS circuit breaker catch errors after tasks are healthy?

No. It only looks at tasks reaching RUNNING and passing load balancer, Cloud Map or container health checks. To roll back a release that is healthy but returns errors, add CloudWatch alarms to the deployment configuration with rollback enabled.

How do I catch a bad release before it reaches ECS with Encore?

Run the change with encore run and the tests locally, then let the pull request's preview environment, hosted by Encore, exercise it in the cloud before merging. Encore deploys to Fargate with rolling updates and health check grace periods, so a release that does start is replaced gradually.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders