In development, a schema change feels instant: change the model, run the migration, deploy, move on. Production rarely works like that. A new version doesn't replace every old instance at once; during a rolling deploy, old and new binaries serve traffic side by side. Background workers restart later. Queued jobs were created by the old version. Read replicas lag. A backfill may still be moving historical data while the new code has already started writing a different shape.
So for a while, both versions need the same database to make sense. Suppose version 2 expects users.display_name and version 1 still expects users.full_name. This migration is correct for v2 and disastrous for v1:
ALTER TABLE users
RENAME COLUMN full_name TO display_name;
If your orchestrator deliberately keeps old instances running until the new ones are healthy, this migration has just broken the very safety net the rollout was meant to provide. That's the shift in thinking that helped me most: a production schema migration isn't just a database change. It's an agreement about compatibility between application versions, stored data, workers, replicas and deployment tooling. In the deployment pipelines I've worked on, the part that mattered wasn't whether the migration command succeeded; it was whether everything stayed correct while the migration was only partly done.
The compatibility window
Midway through rolling out version 2 across ten instances, production looks like this:
That's normal and usually what you want: gradual replacement, health checks and easy rollback (I wrote about the traffic side of this in Why Can a Successful Kubernetes Rolling Deployment Still Drop Requests?). The consequence is that the database has to support old and new code at the same time, so a schema can be perfectly valid in its final form and still unsafe to apply in one step.
The questions aren't just "will v2 work with the new schema?" but also: will v1 still work after the first migration? Will v2 understand rows written by v1? Will old workers understand rows written by v2? Can we roll back while this schema exists? Can a paused backfill safely resume tomorrow? A production migration is defined as much by its in-between states as by where it ends up.
Destructive changes break things first
Dropping a column that's "no longer used" is the simplest example. Version 1 still maps it:
@Entity
public class PullRequest {
@Column(name = "legacy_status")
private String legacyStatus;
}
The team decides nothing reads legacy_status anymore and drops it:
ALTER TABLE pull_requests
DROP COLUMN legacy_status;
The DDL succeeds. Then the ORM generates a query that still selects the column, and the application fails, even though nobody wrote code that reads it.
This is exactly what GitHub describes in its August 2025 availability report. A migration dropped a column from a table behind pull requests; it wasn't in direct use, but the ORM still referenced it in some queries, causing errors across pushes, webhooks, notifications and pull requests. A similar drop on a table behind Copilot caused a second incident, and GitHub temporarily blocked all drop-column operations while adding safeguards.
"Our new code doesn't use the column" isn't enough evidence that it can go. Before removing anything, I want confidence that it's no longer needed by old application versions, ORM metadata, background workers, scheduled and queued jobs, analytics and exports, replica consumers, admin tools, or rollback. That's why destructive changes belong at the end of a migration, not the start.
Expand and contract
The safer general strategy is expand and contract. Instead of jumping straight from the old shape to the new one, you add an intermediate state that both versions understand, move everything across, and only then remove the old shape.
Expansion should be backward compatible; contraction happens only once nothing depends on the old shape. For the rename, start by adding the new column:
ALTER TABLE users
ADD COLUMN display_name VARCHAR(255);
Old code keeps using full_name, new code can start using display_name, and nothing has been destroyed. Note that it's nullable. Adding it as NOT NULL straight away would fail for every existing row, and old code doesn't know it's supposed to fill it in. The first migration should create a possibility, not impose a requirement; the stricter constraint can come later. Constraints have their own surprises: Shopify's article on safely adding NOT NULL columns shows how defaults, strict SQL modes, existing rows and online schema-change tools interact on live MySQL tables.
Next, deploy code that reads both, preferring the new column and falling back to the old one, so it handles rows that haven't been migrated yet:
function getDisplayName(user: User): string {
return user.displayName ?? user.fullName;
}
Then have new code write both during the transition:
await db.users.update({
where: { id: userId },
data: {
fullName: input.name,
displayName: input.name,
},
});
While v1 and v2 overlap, v1 writes only the old column and v2 writes both. If both columns are in the same database, write them in one transaction so they can't diverge. If the old and new models live in separate systems, the migration has become a distributed-write problem, and you may need an outbox, replay, reconciliation or repair jobs to keep them in step. A migration can temporarily increase how much consistency work the system has to do, so keep the dual-write period short and deliberate rather than letting it become permanent by accident.
New writes now fill both columns, but historical rows are still incomplete. That's what the backfill is for.
Backfills are production traffic
The naive backfill is one statement:
UPDATE users
SET display_name = full_name
WHERE display_name IS NULL;
On 500 rows, that's fine. On hundreds of millions, it means long transactions, heavy write I/O, replication lag, WAL or binlog growth, lock pressure, cache churn and extra CPU. A safer approach migrates bounded ranges, using the primary key as a cursor:
UPDATE users
SET display_name = full_name
WHERE id > :last_id
AND id <= :next_id
AND display_name IS NULL;
Avoid OFFSET for this. LIMIT 1000 OFFSET 10000000 makes the database walk past ten million rows to find the next batch, and it gets slower as you go. Keyset pagination (WHERE id > :last_processed_id ORDER BY id LIMIT 1000) stays fast, and last_processed_id doubles as a checkpoint, so the job is easy to pause and resume.
Assume the backfill will be interrupted by a crash, a deploy, an operator pausing it, a failover, throttling or maintenance. The display_name IS NULL condition makes each step safe to repeat; already-migrated rows are left alone. The mindset is "I might stop anywhere and carry on later", which matters a lot once a migration runs for hours or days.
To the database, a "background" backfill uses the same resources as customer traffic: connections, CPU, I/O, locks, buffer cache and replication bandwidth. GitHub's May 2026 availability report shows what that means. A routine online schema migration on a large, busy table had run without trouble for hours, but as traffic rose toward the weekly peak, the migration plus normal load saturated database connection capacity and caused cascading timeouts. Their follow-up: align large migrations with low-traffic windows, throttle dynamically based on live cluster load, add circuit breakers that pause migrations when latency or connection usage crosses safe thresholds, and monitor migration-induced pressure.
So rather than a fixed "1,000 rows, sleep 100 ms" loop, I'd let the backfill defer to production health:
while (hasMoreRows()) {
const health = await databaseHealth();
if (
health.cpu > 75 ||
health.connectionUsage > 70 ||
health.replicationLag > MAX_REPLICATION_LAG
) {
await sleep(5000);
continue;
}
await migrateNextBatch();
}
The migration behaves like a low-priority tenant, and customer traffic wins. Not every migration needs a clever control loop, but its speed should be limited by the health of the database it's sharing.
Measure the state of the data, not just whether the worker is alive. "Job completed successfully" says little about whether the migration is complete or consistent. I'd rather see rows total, migrated and remaining, mismatch count, rate and estimated completion, next to database CPU, connection usage, replica lag, lock waits, query latency and application errors. The job is just the mechanism; the state of the data is the migration.
Validate, then switch
When the backfill reports 100%, I still don't delete the fallback. First, check the data:
SELECT COUNT(*)
FROM users
WHERE display_name IS NULL;
SELECT COUNT(*)
FROM users
WHERE display_name IS DISTINCT FROM full_name;
Both should be zero. Depending on the migration, validation might also include checksums, sampled comparisons, shadow reads, comparing old and new code paths, and domain-specific checks. Stripe's Online migrations at scale describes migrating hundreds of millions of Subscription objects with a four-step dual-write pattern, and using GitHub's Scientist library to compare old and new read paths before trusting the new table. A finished backfill isn't the same as a validated one.
Once validation looks good, switch reads gradually. A feature flag separates deploying code from turning on the behaviour:
if (flags.readDisplayName) {
return user.displayName;
}
return user.fullName;
Roll it out to 1%, 5%, 25%, 50% and then 100% of traffic while watching errors, null rates, mismatches and latency. If the new path misbehaves, you can turn off the flag without rolling back the whole binary.
When new reads are stable, the backfill is complete and old versions are gone, the current code can stop writing full_name. Even then I wouldn't drop it straight away, because rollback may still need it.
Rollback decides when cleanup is safe
Rollback sounds simple: v2 is broken, redeploy v1. But v1 still needs full_name. If the column is already gone, v1 is no longer a valid rollback target. A deployment isn't safely reversible if the schema no longer supports the version you'd roll back to.
It helps to think of two phases. While both columns exist, the migration is reversible: either version has what it needs. Once the old column is dropped, it's irreversible, and recovery means fixing forward rather than redeploying the old binary. That's why destructive cleanup deserves a higher bar than additive changes. I'd only drop the column once there are no old instances, workers, jobs or code references left, the new data is validated, and the rollback window has passed:
ALTER TABLE users
DROP COLUMN full_name;
The whole sequence looks like this:
That might take several deployments. It isn't wasted ceremony; each step buys compatibility and the ability to go back.
Indexes and constraints
Column changes aren't the only ones that need this care. Adding an index is logically additive, but the PostgreSQL CREATE INDEX docs note that a normal build blocks writes to the table while it runs. On a busy table, use the concurrent form instead:
CREATE INDEX CONCURRENTLY idx_orders_customer
ON orders(customer_id);
That lets writes continue, at the cost of more total work, a longer build and extra failure cases (a failed concurrent build leaves an invalid index to clean up). Less blocking isn't free: an online migration still scans data, uses CPU and I/O, affects replicas and competes with production.
Constraints can be staged too. ALTER TABLE lets you add a constraint as NOT VALID, which enforces it for new rows without scanning existing ones, and validate the history later:
ALTER TABLE orders
ADD CONSTRAINT orders_customer_fk
FOREIGN KEY (customer_id)
REFERENCES customers(id)
NOT VALID;
ALTER TABLE orders
VALIDATE CONSTRAINT orders_customer_fk;
Where the database supports it, separating "stop new bad data" from "prove all old data is good" makes big changes much easier to operate.
The other consumers of your schema
A plan can look perfect from the main API's point of view and still be unsafe, because the API isn't the only thing reading the schema.
ORMs hide assumptions. After business logic stops calling user.getFullName(), the ORM may still select the column, expect it when building objects, or keep it in model metadata. That's the GitHub incident above. Cleanup needs more than a grep for the column name; generated SQL is part of the surface too.
Workers outlive deployments. Even once every API instance is on v2, there may be scheduled reports, Kafka consumers, SQS workers, cron jobs, exports, admin tools and long-running batch jobs. A queue may still hold work created by v1, a delayed job may run hours later, a worker may restart from an old artifact, and an export may read from a replica. The real compatibility window lasts until every code path that can touch the schema understands the new shape, which can be much longer than the visible rollout.
None of these change at the same moment. Some cache schema or ORM metadata, some have delayed work, replicas lag, and an old binary may come back briefly during rollback. A migration has to tolerate that time skew, which makes it a distributed-systems problem: the schema is shared state, and each version is a participant with its own expectations of it.
It helps to treat the schema like an API. We're careful when changing REST endpoints, event schemas or public SDKs, because some consumer might still depend on the old contract. Dropping a column is like removing a field from a public API: maybe every consumer has moved on, maybe one hasn't, and the database can't tell until that consumer fails. The useful questions are the same ones you'd ask about an API: who uses this field, which versions are still running, what do we promise during rollout, how do we deprecate it, and how do we know nobody needs it anymore?
The migration as a state machine
Migration tools encourage thinking of a change as one file, like 20260927_rename_full_name.sql. That's useful for versioning, but it makes the migration feel more atomic than it is. In reality it's a sequence of states, each with its own compatibility guarantees and rollback options:
That changes review conversations for the better. Instead of "does this SQL look safe?", you can ask which state we're entering, which binaries work in it, which writers are allowed, what can still be rolled back, and what proves it's safe to move on.
It also tells you what to test. Not just "new schema plus new code", but the in-between combinations: the expanded schema with old code, a mixed fleet, new code against partly backfilled data, and the new schema with a stale worker. Any state that can exist in production is a supported state during the migration. For bigger changes, I like writing the compatibility contract down:
| Application version | Old schema | Expanded schema | Final schema |
|---|---|---|---|
| v1 | Compatible | Compatible | Incompatible |
| v2 (transitional) | Not intended | Compatible | Compatible |
| v3 (final) | Incompatible | Compatible | Compatible |
The dangerous combination is obvious at a glance: v1 with the final schema. So the destructive migration can't run while v1 might still exist anywhere in production. That's much clearer than "make sure the migrations run in the right order".
Key takeaways
- During a rolling deploy, old and new code share the database. Every intermediate schema state has to work for both.
- Use expand and contract: add nullable columns first, read both, write both, backfill, validate, switch reads behind a flag, and drop last.
- Treat backfills as production traffic. Use small keyset batches, make them idempotent and resumable, and throttle on database health.
- Don't drop anything until old versions, workers, jobs and ORM mappings are gone and the rollback window has closed.
- Use online DDL like
CREATE INDEX CONCURRENTLYandNOT VALIDconstraints, but remember they still cost resources. - Write down which versions work with which schema states, and test those combinations.
References
- GitHub — Availability report, August 2025 — two incidents where dropped columns were still referenced by the ORM.
- GitHub — Availability report, May 2026 — an online schema migration that, combined with peak traffic, saturated database connections, and the throttling and circuit breakers added afterwards.
- Stripe — Online migrations at scale — the four-step dual-write pattern used to migrate hundreds of millions of objects, with Scientist for comparing read paths.
- Shopify Engineering — Safely adding NOT NULL columns to your database tables — the subtle risks of adding constraints to live MySQL tables.
- PostgreSQL — CREATE INDEX — normal versus concurrent index builds and their trade-offs.
- PostgreSQL — ALTER TABLE —
NOT VALIDandVALIDATE CONSTRAINTfor staged constraint checking.
