Schema Changes Need a Compatibility Window
Ship generated schema changes safely by planning mixed-version compatibility, restartable backfills, and rollback boundaries before removing old fields.
A correct final schema can still break deployment
A coding assistant can produce a coherent application patch and a matching database migration while leaving the transition between versions unsafe. The new application works with the new schema. The old application works with the old schema. During deployment, however, both application versions may run concurrently, and background workers may lag behind the web service. Correct endpoints do not establish a correct path between them.
Schema review should therefore include a compatibility window: the period in which old and new representations coexist under explicit read and write rules. The important artifact is not just the final table definition. It is the sequence of states through which the application and stored data can pass without violating the agreed behavior.
The example below is an illustrative design exercise for a conventional application database. It is not a product capability claim or a database-specific migration recipe. Actual transaction behavior, locking, and deployment mechanics must be verified for the chosen system. The purpose is to expose requirements that a generated patch can omit even when its final code looks internally consistent.
Start with a representation change that preserves meaning
Suppose an application stores a timeout in an integer field named timeout_seconds. The new version uses timeout_ms so it can eventually represent finer-grained values. Existing values must be multiplied by 1,000. Initially, the application continues to accept only whole-second inputs; otherwise, the old representation cannot express every newly permitted value.
That restriction is crucial to rollback. If the new version begins accepting 1,500 milliseconds while the old version understands only whole seconds, converting backward requires rounding or another policy. The deployment has crossed a semantic boundary, not merely changed a column name. A rollback plan must say whether such values are prohibited during coexistence or how their meaning is preserved.
Also define valid ranges and overflow handling before migration. Multiplication can exceed the destination type's range even when the source value was valid. The design should reject or quarantine incompatible records according to an explicit policy rather than relying on accidental numeric behavior. No particular integer width is assumed in this example.
Specify readers and writers separately
An expansion phase adds the new field while retaining the old one. During coexistence, readers need a rule for choosing a representation, and writers need a rule for keeping representations consistent. Merely saying dual write is insufficient. Two separate writes can diverge if one succeeds and the other fails, unless the system provides and uses an appropriate atomic update mechanism.
One possible transitional design keeps the old field authoritative until all old writers are retired. New code reads the old field and converts it, while writing both fields atomically where supported. The new field is populated and checked but is not yet trusted as the sole source of truth. This costs extra work but avoids assuming that legacy writers maintain a field they do not know exists.
After old writers stop, a reconciliation pass repairs any new-field values that no longer match the authoritative old field. Only then does the team switch authority to the new representation. If old readers remain, the system must still preserve the old representation and its restricted expressiveness until those readers are retired as well.
Inspect compatibility as a matrix
In the fictional release, version V1 requires only timeout_seconds. Version V2 is the transitional application and still requires that old field while also using the added field. Version V3 uses only timeout_ms. The old schema contains only seconds; the expanded schema contains both; the contracted schema contains only milliseconds.
The matrix below marks structural compatibility under those definitions. It deliberately does not claim that every compatible combination has correct data. A V3 process can find its required field in the expanded schema while still reading incomplete values if authority was switched before reconciliation. Structural compatibility is necessary here, but not sufficient.
Figure 1 — The expanded schema supports all three versions structurally, while contraction removes the rollback path to V1 and V2. Source: Illustrative field requirements; 1 means required fields exist.
Make the backfill restartable and race aware
Assume the fictional table contains 12,000 records and the backfill processes batches of 1,000. With a fixed population and no retries, that requires 12 batches. A progress checkpoint should identify a stable traversal position, not just a count of rows processed. Counts alone cannot distinguish repeated work from coverage of new records.
Each batch must tolerate restarting after an uncertain outcome. If the worker loses its connection after committing, retrying should not corrupt already converted values. An assignment derived from the authoritative seconds field is different from repeatedly multiplying the current milliseconds field. The latter can compound the conversion on retries and is unsuitable for this migration.
Concurrency adds another hazard. A backfill can read an old seconds value, then overwrite milliseconds after a newer application update has changed both fields. Avoid this with a database-appropriate consistency mechanism, such as a conditional update against the observed source version or a suitable transactional approach. The correct mechanism depends on the database and workload; the race must be addressed explicitly.
The next chart shows an idealized progress path for the fixed 12,000-record population. It assumes each batch completes successfully and no records are added. It is useful for checking arithmetic, but operational completion must also account for concurrent updates and reconciliation, which a processed-row count cannot prove.
Figure 2 — Twelve successful batches cover the fixed illustrative population; reaching 12,000 does not establish consistency after concurrent writes. Source: Illustrative batch arithmetic with 1,000 records per batch.
Define the switch in terms of evidence
The authority switch needs evidence that old writers have stopped and the new representation is complete and consistent. Inventory all write paths, including scheduled jobs, repair utilities, and delayed consumers. Observing that the main web deployment is current does not establish that every writer is current. A forgotten background process can recreate divergence after a successful backfill.
Reconciliation should compare the representations under the migration's conversion rule and report missing or mismatched values. Investigate mismatches rather than blindly overwriting them after authority changes. Before the switch, seconds is authoritative in this design. After the switch, applying the same repair direction could destroy valid millisecond data. The direction of repair is part of the migration state.
Keep the authority state controlled and observable. If different instances infer it independently from whether a column happens to be populated, they can disagree during partial backfill. A coordinated release condition or explicit migration phase makes the intended behavior reviewable. Test how an instance behaves when its local configuration is stale.
Before the switch, also check recovery tooling. A restored backup may contain an older migration phase than the application currently expects. Recovery instructions should pair the restored data representation with a compatible application version, then describe how to resume reconciliation. A backup that exists but cannot be brought through the compatibility sequence leaves an important operational assumption untested.
Remove the old representation last
Contraction should occur only after old readers and writers are retired and the rollback policy has changed accordingly. Removing the old field makes a rollback to code that requires it impossible without a restoration step. Separately, allowing subsecond values may make semantic rollback impossible even while the old field still exists. These are two different boundaries.
Rehearse recovery at each phase using representative data and the actual deployment mechanism. An expansion failure may permit returning to V1. A failed authority switch may require preserving both fields while correcting divergence. A post-contraction problem may require rolling forward or restoring a compatible schema. Calling every response rollback obscures these differences.
Review generated migrations as operational protocols. Ask which versions coexist, which representation is authoritative, how retries behave, and what evidence permits the next transition. When those answers are explicit, the final patch becomes only one part of a complete change. The deployment can then preserve meaning throughout the transition instead of discovering compatibility requirements after old and new code meet in production.