Pre-release: the store is not open yet and nothing is for sale. What early access means

Incident write-up

Every deploy gave our visitors 503s. Then the fix caused a 503 during a rollback.

Short version: docker compose up -d recreated all replicas of our app at the same moment, and for about 15 seconds the proxy had nothing to send traffic to. We fixed it by replacing replicas one at a time and renaming the new containers back to fixed names the proxy knew. The renaming was the next outage. The lasting fix: never rename, let the proxy find replicas by DNS.

The first problem: all replicas restart at once

Our site runs three replicas of the app behind Caddy. Deploys ended with docker compose up -d. Compose saw a new image and recreated all three at once. Each new container needs some seconds before it answers. During that window the proxy had no healthy upstream and answered 503 no upstreams available.

We did not notice for weeks because the deploy itself "worked". We noticed by reading the proxy log. Over four days we counted 13 bursts of 503s, and 12 of them fell in the same minute as a deploy: 222 failed requests, 84 of them from real visitors. In one deploy the three replicas started at the same second, and 503s followed for 14 seconds.

The first fix

Replace one replica at a time: stop replica 1, start a new one, wait until it answers, wait for the proxy to notice it, then do replica 2. The other two keep serving.

There was a catch. When compose adds a replica it gives it the next number: web-4, not web-1. Our Caddy config listed the containers by name (web-1, web-2, web-3), and so did a few other scripts. So the new container was renamed back to web-1 with docker rename. It worked. The 503s at deploy time stopped.

The second problem: the rename

The next day a deploy had to be rolled back. The rollback script did what rollback scripts usually do: point the tag back to the old image and run docker compose up -d.

Compose does not know about renames. It recreated the replicas under its own numbering: web-4, web-5, web-6. The names Caddy was configured with no longer existed, and the site answered 503 until someone renamed the containers by hand. It happened during a rollback, the moment the site was already in trouble.

The same trick caused another 503 a month later. A fix that depends on every script remembering a rename is not a fix.

The lasting fix

Stop fighting compose over names. Names and numbers belong to compose.

  • The proxy finds replicas through Docker's DNS, by a network alias, not by container names. Caddy's dynamic a upstream re-resolves every second; nginx can do the same with resolver 127.0.0.11; Traefik follows containers by labels. Whatever compose names the containers, the proxy follows.
  • Scripts find replicas by compose labels (project and service), never by name.
  • Replacement is "add one, then remove one": scale to N+1 with --no-recreate (the new replica uses the new image), wait until it is healthy, give the proxy a few seconds, stop one old replica gracefully, remove it, repeat. Capacity never drops below N.
  • If a new replica is not healthy, remove it, point the live tag back at the old image and replace back. Live stays on the old version.
  • Rollback uses the same replacement, not a plain up -d.

The general rule

If your proxy knows container names, any tool that recreates containers can take your site down, including your own rollback. Make the proxy follow the service, not the containers.

What we built from it

Ship Gate's deploy replaces replicas exactly as above and never calls docker rename. Its test suite runs against a fake Docker that records every command, and checks that a new replica is always added before an old one stops, that the running count never drops below the replica count, and that rename is never called. Rollback goes back to the image that was actually live before, without a rebuild. (So far the deploy part has been tested against a fake Docker, not on a real server; see the product's limitations before you use it in production.)

Checklist for your own setup

  • Does your proxy config contain container names? Replace them with a network alias.
  • What does your rollback run? If it is a plain docker compose up -d, it recreates everything at once.
  • Read your proxy log around your last deploy minute. Any 502/503?
  • Does your app finish in-flight requests on SIGTERM?

What we built from it

Ship Gate

Runs your checks on the exact commit you are about to ship and refuses to deploy anything the checks did not see. Open-source core.

More incidents

Other things that broke.

All incidents