Skip to content

Lesson 12 of 13 · 14m

Half Your Fleet Is Always Behind

A rolling deploy is a window where N and N−1 coexist, so every contract — schema, wire format, API — must be compatible in both directions.

A rolling deploy is not a state transition. It is a window — minutes on a small fleet, hours on a large one — during which version N and version N−1 serve traffic simultaneously. On a fleet that deploys daily, the "everyone runs the new code" state is the brief exception, not the rule. The implication that bites: every contract two versions share — the schema, the message format, the API — has to work in both directions for the whole window.

The expand-migrate-contract answer

Schema changes get a standard recipe precisely because the naive one breaks the window. Renaming users.email to users.primary_email in one release means old code reads a column that no longer exists and new code reads one that does not yet — somebody errors for the entire rollout. The recipe instead:

  1. Expand: add primary_email as a new nullable column. Deploy code that dual-writes both columns.
  2. Migrate: backfill old rows.
  3. Contract: switch readers to primary_email, deploy, and drop email in a later release — never in the deploy that stops writing it.

Every step is independently safe under a mixed fleet, which is the entire point. Postgres adds a landmine worth knowing by name: ALTER TABLE takes an ACCESS EXCLUSIVE lock, so a migration that queues behind a long transaction blocks the table — set lock_timeout and retry rather than serialize your deploy behind someone else's analytics query. For zero-downtime reshaping, pg_repack rebuilds tables online; on MySQL, gh-ost (GitHub's own tool, built for exactly this) and pt-online-schema-change do the shadow-table dance.

Wire formats obey the same logic. Protobuf's rule is mechanical: never reuse field numbers; mark deleted fields reserved so the next contributor cannot reintroduce the number with a new meaning. Old consumers must ignore unknown fields — that is what the binary format is for — and new code must tolerate records written before it existed. Forward and backward compatibility, at once, for as long as the rolling window lasts. JSON is friendlier about it — unknown keys are free to ignore — and more dangerous: JSON types invite coercions (a field that flips from string to int mid-fleet) that protobuf's numbered, typed fields make unrepresentable.

The ordering rule that follows: tolerant consumers deploy before producers. The version that understands both shapes goes out first; only then does anyone emit the new shape. Reverse the order and you guarantee a window where writers produce bytes no reader can parse — the failure is not probabilistic, it is scheduled.

Deploy and activate are different verbs

Feature flags decouple "the code is everywhere" from "the code is live." Rollout order stops mattering; rollback stops being a redeploy — it is a flag flip, which is the difference between a 30-second mitigation and a 20-minute one while the error budget burns. Flags do not remove the compatibility requirement: the flag-off path still has to coexist with the flag-on data the other half of the fleet is writing.

And "we can just roll back" deserves the same scrutiny as the lock without a fence. Rolling back to a version that cannot read the data the new version already wrote is not a rollback — it is a second outage with extra steps. The two-deploy rule covers it: a contract change takes at least two deploys, one where both sides understand both shapes, and only then a deploy that drops the old shape.

What to actually do

Additive changes first; removals always one deploy behind; lock_timeout on every DDL statement; consumers that read both shapes before producers stop writing the old one; flags on risky paths; and a CI job that runs the previous release's test suite against the new build — because the compatibility that matters is the one between versions, and that is precisely the test nobody writes unless someone makes them.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.