Q24 · What’s your strategy for schema evolution without downtime?
Back to 24 Architecture Questions.
The question is not “run a migration tool”. The axis it turns on: how many versions of the shape must be readable at once. A rolling deploy forces the answer to at least two: the old code and the new code read and write the same data simultaneously, for the whole duration of the release. Schema evolution without downtime is the discipline of designing for that window instead of discovering it.
What the answer should contain
The answer to the axis is “two, always”. Old and new code coexist during every rolling deploy, on the same data. Sometimes more than two: slow consumers on a stream, offline mobile clients, partner integrations nobody remembered. The design counts the readers and keeps every shape they still read.
Expand, migrate, contract, never combine. Expand: add the new column or field; old code ignores it, new code writes both. Migrate: backfill in throttled batches, outside the request path. Contract: remove the old shape only after the last old reader is provably gone. The cardinal sin is repurposing or renaming in place: the instant you change a field’s meaning, every old reader is silently wrong.
Make two-version readability cheap with parser discipline. Readers ignore unknown fields (forward compatibility); writers tolerate absent ones and every field has a meaningful default or an explicit “absent”. With those two habits, “additive change” works for databases, JSON, protobuf, and event schemas alike.
Databases migrate online, not at 2 a.m. with an ALTER. Create the new structure, dual-write or use the database’s online schema change tool (create, copy, swap), backfill in the background with load-aware throttling, then drop the old. A blocking ALTER on the hot table is downtime, whatever the maintenance window calls it.
Streams and queues extend the window. A consumer lagging by hours reads shapes the producer retired hours ago. Schema registries with compatibility rules are the enforcement: the registry rejects the change that would strand a live consumer, before it ships.
Prove it in CI. Read old data with new code, write new data with old code, and fail the build on a parse error. Version tolerance is a test, not a vibe.
Ideas worth mentioning out loud
- “Schema evolution is a deploy problem that shows up as a data problem. The data must serve two readers for one release cycle, and the whole strategy is budgeting that window.”
- The contract step is the one everyone skips, and the skipped contracts are where old shapes pile up: every unused column in a hot table is a write tax on every insert, and nobody has been paid to remove it. The same ratchet, at schema level.
- Know who your readers are: metrics on version usage, not assumptions. “Old clients are gone” is a claim; the version counter is a fact.
Follow-ups to expect
- How long do we dual-write? Until the last old reader is provably gone: version usage metrics decide, not the calendar.
- How do renames work? New field with the new name, backfill, migrate readers, then contract the old field. Never reuse the old name for new meaning.
- What about document stores, where there is no schema? Same protocol, plus per-record drift: readers must tolerate five shapes of the same record, because nothing enforced one shape. The window never closes on its own.
Red flags in an answer
- A destructive change shipped in the same release as the code that wants it.
- “We deploy fast, the window is tiny.” The window exists; its size is not the argument.
- A big-bang ALTER on the live table, scheduled for a quiet hour.
- No way to tell which reader versions are still alive.
- A required field added with no default, stranding every old writer.
Sources
- Zero-downtime database schema migration strategies, Bytebase: expand and contract in current practice, including the batching and throttling details of the backfill step.
- gh-ost, GitHub: the online migration tool GitHub built for its own MySQL fleet, a production implementation of the create-copy-swap mechanics.
- Schema Registry overview, Confluent: compatibility rules that reject the producer change that would strand a live consumer, which is the two-version window enforced on streams instead of assumed.