Platforms

Blue-green deployments without the 3 a.m. rollback

Blue-green is easy to draw and hard to run at 03:00. The difference is connection draining, health gates that fail closed, and a migration rule that keeps both colours compatible for a full release.

Every team that adopts blue-green meets the same edge case: a green stack that is healthy on every dashboard, yet serves errors for ninety seconds after cutover. The cause is rarely the application. It is sockets established against blue and held open by clients, load balancers and keep-alive pools, while the new colour has no idea those connections exist.

Draining is a state machine, not a sleep

A fixed sleep 30 between "stop sending traffic" and "stop the old stack" is a guess. WebSocket sessions, HTTP/2 multiplexing and upstream keep-alive pools all extend connection lifetime beyond it. We model drain as three observable states:

  • Stop admitting. Remove the colour from the load balancer and answer new work with 503, never a silent drop.
  • Wait for zero. Poll active connections until the gauge is flat across two scrape intervals.
  • Force with a bound. Past a hard ceiling, terminate remaining sockets and log each one with its age and peer.

Measured default

On our traffic mix the p99 drain is 26 seconds, but WebSocket workloads need the 180-second ceiling. That number belongs in pipeline configuration, not in a wiki page.

Health gates that fail closed

Passing /healthz proves the process is alive. It does not prove the new colour can reach the database, refresh its cache or validate its certificate. Our gate sends synthetic requests down the real user path, then compares error rate and p95 with the old colour for five minutes before traffic is allowed to move.

# synthetic gate against green before any traffic moves
for i in $(seq 1 30); do
  curl -fsS --max-time 2 -o /dev/null \
    -w "%{http_code} %{time_total}\n" \
    https://green.internal/ready?probe=gate
  sleep 10
done
# one non-200 line fails the pipeline

The gate fails on a single non-200. A colour that is "mostly healthy" is a colour that will page someone later.

Schema changes: expand, migrate, contract

The application switch is only safe when the database is compatible with both colours. We split every migration into three releases and never combine them into one deployment:

PhaseChangeRollback
ExpandAdd nullable column, new table or new index concurrentlyAdditive, safe to leave
MigrateDual-write both paths, backfill in batchesDisable the flag
Cut overReads move to the new fieldFlip reads back
ContractDrop the old column after one full releasePoint of no return

Contract is the only irreversible step, which is why it waits a release. Dropping a column in the same deploy that stops using it removes the rollback path exactly when you are most likely to need it.

Exit criteria, written before the deploy

We write the abort conditions into the change ticket: error rate above 0.5 percent for two consecutive minutes, p95 above 1.8 times baseline, or any 5xx from the synthetic probe. The person on shift follows the ticket instead of debating thresholds at 03:00.

Do not skip

If the old colour is already destroyed when the new one fails, this is not blue-green. Keep the previous release runnable until the soak window closes, including its configuration and migrations.

Previous noteOptimizing Linux TCP congestion control