← Back to the blog

AWS & n8n • 2026-07-23 • 3 min read

Zero-Downtime ECS Deploys: Health Checks That Mean Something

The thin band of 502s on every release is not inevitable. It comes from four settings that disagree with each other, and a health check that returns 200 before the service is ready.

Zero-Downtime ECS Deploys: Health Checks That Mean Something — AWS & n8n

Most teams have a deploy that shows a small spike of 5xx and have decided it is the cost of shipping. It is not. It is a handful of timeouts that do not agree.

The two health checks are different

A single /health returning 200 is the root of most of this.

Liveness answers "should this container be killed and replaced". It must not check dependencies. A health check that returns unhealthy because the database is slow will cheerfully restart every task you have during a database incident, turning a degradation into an outage.

Readiness answers "should traffic be sent here". It checks that the process has finished starting: configuration loaded, pool connected, caches warm. The load balancer uses this one.

// rust
// Liveness: the process is alive and the runtime is responsive.
async fn livez() -> StatusCode { StatusCode::OK }

// Readiness: this instance can serve a real request right now.
async fn readyz(State(app): State<AppState>) -> StatusCode {
    if app.db.is_connected() && app.keys.is_warm() {
        StatusCode::OK
    } else {
        StatusCode::SERVICE_UNAVAILABLE
    }
}

The ordering that removes the 502s

A task being replaced must stop receiving new requests *before* it stops accepting them. The sequence:

  1. ECS deregisters the task from the target group
  2. The load balancer finishes draining in-flight requests — deregistration_delay
  3. ECS sends SIGTERM
  4. The process stops accepting new connections, finishes what it holds, exits
  5. If it has not exited by stopTimeout, it is killed

The failures come from these disagreeing. deregistration_delay shorter than your longest request means the balancer gives up mid-request. stopTimeout shorter than your graceful shutdown means the orchestrator kills a process that was draining correctly. Our rule: stopTimeout > graceful shutdown > request timeout, and deregistration_delay at least the request timeout.

The application side of this is the shutdown signal described in the axum production setup. Both halves are required; either alone does nothing.

Settings that matter

  • minimumHealthyPercent: 100 and maximumPercent: 200 — start the new tasks before stopping the old ones
  • Health check grace period longer than a cold start, or the first task is killed while still warming up
  • Circuit breaker with rollback enabled, so a failing deploy reverts without a human
  • A target group health check interval tight enough to notice quickly, with a threshold high enough not to flap

Migrations

The deploy will run both versions at once, for a minute or for an hour. Every schema change must therefore be backward compatible with the version still running: add columns, do not rename them; write both, read one; drop only after the old version is gone. This is a constraint on how you write migrations, not a deployment setting, and it is the one people discover the hard way.

Prove it

Run a load generator against the service and deploy. If you cannot see the deploy in the error rate, it works. If you can, one of the four numbers above is wrong — and now you know which afternoon to spend.

Read next

COOKIES // MEASUREMENT

We count page views through Google Tag Manager. Say yes and it may store a cookie in your browser; say no and it still counts the visit, without storing anything and without an identifier. Nothing here is used for advertising.

Cookie Policy — you can change this at any time from the footer of any page.