Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Define the company process for database schema changes so that hundreds of deploys per week never cause downtime.

The process rests on one rule: every migration must be backward compatible with the application version already running, so changes follow expand and contract and nothing destructive ships in the same release as the code that stops using it. We enforce the rule with automation: a linter that flags dangerous operations, CI that tests the previous application version against the new schema, long backfills separated into throttled jobs, and a database review with a runbook and rollback plan for changes to large tables.

Why this question is asked

At a few deploys a week, schema changes can be handled by careful people. At hundreds of deploys a week across many teams, careful people are not enough: someone will add a column with a volatile default to a hot table, or drop a column one release too early, and the site will go down on a Tuesday afternoon. Interviewers ask this design question to see whether we can turn hard-won lessons into a process that works without heroes. In this answer, we will define the compatibility rule, then design the automated checks, the handling of backfills, the backward compatibility test in CI and the review path for large tables.

1The Rule Everything Else Follows

With continuous deployment, a migration runs while the previous application version is still serving traffic, and a rollback can bring that version back after the migration. So the process starts with a single rule: every migration must work with both the current and the previous application version. That rule turns into the expand and contract pattern. We first expand the schema with additions that old code ignores, such as new nullable columns, new tables and new indexes. Then we move the code over. Only in a later release, after no deployed or rollback-candidate version uses the old structure, do we contract by dropping or tightening it.

The most important consequence is a release boundary: a destructive change, such as dropping a column, renaming one or adding a NOT NULL constraint, is never in the same release as the code change that stops depending on the old shape. Writing that down as a rule, with examples, is the first part of the process.

2Lint Every Migration for Dangerous Operations

Most dangerous migrations fall into a small number of patterns that a tool can recognise in the SQL. A migration linter runs in CI on every pull request that adds a migration and fails the build, or asks for an explicit override, when it finds one. For PostgreSQL, open-source linters such as squawk already cover many of these rules, and teams can add their own.

Rules a migration linter enforces
Dangerous operationWhy it hurtsSafe alternative
CREATE INDEX without CONCURRENTLYblocks writes until builtCREATE INDEX CONCURRENTLY, non-transactional
ADD COLUMN with volatile defaultrewrites the table under a strong lockadd nullable, backfill as a job
SET NOT NULL on a large tablefull scan under ACCESS EXCLUSIVECHECK NOT VALID, validate, then SET NOT NULL
DDL without lock_timeoutcan queue and block all trafficSET lock_timeout at the top
DROP or RENAME COLUMNbreaks the running versionexpand and contract over releases
ALTER COLUMN TYPEoften rewrites the tablenew column, backfill, switch
Large UPDATE in a migrationlong locks, WAL, replica lagthrottled backfill job

Notice that every rule comes with a safe alternative, which is what makes a linter helpful rather than annoying. An override with a written reason is allowed, for example for a table known to be tiny, and the reason is recorded in the pull request so reviewers see it.

3Separate Backfills From Schema Migrations

Schema migrations should be fast: seconds, not hours. Data backfills, where we compute or copy values into existing rows, can take hours on large tables and need to be paused, throttled and resumed. So the process says that migrations change structure, and backfills run as separate jobs from a shared framework that processes rows in small batches, sleeps between batches, watches replication lag and database load, records its progress and can be stopped at any time.

This separation also makes the deploy pipeline predictable. A deploy that runs a migration finishes in minutes, and the backfill continues in the background, visible on its own dashboard. The step that depends on the backfill, such as making a column NOT NULL, is released only after the job reports completion.

4Test the Previous Version Against the New Schema

A linter catches known patterns, but backward compatibility also depends on the code. The best proof is to run the previous release's tests against the new schema. In CI, the pipeline starts a database of the production engine and version, applies all migrations including the new ones, then checks out the previous release tag and runs its integration test suite against that database. If the new schema breaks the old code, for example because a column it reads was dropped, the build fails before anything reaches production.

Java
# CI job: backward compatibility (simplified)
docker run -d --name db postgres:17
./gradlew flywayMigrate # current branch: all migrations, including new ones
git worktree add ../previous v2026.11.04 # last production release
(cd ../previous && ./gradlew integrationTest -Dspring.flyway.enabled=false \
-Dspring.jpa.hibernate.ddl-auto=validate)
# FAILED: Schema-validation: missing column [mail] in table [customer]

Notice that the previous version runs with Flyway disabled and Hibernate in validate mode: it must accept the new schema exactly as it is. This single job catches most premature contract steps, which are the most common cause of migration outages.

5Reviews, Runbooks and Rollback for Large Tables

Some changes need human judgement, especially on large or very busy tables. The process marks a list of such tables, for example any table over 10 million rows or in the top 20 by query rate, and requires a review by a database owner for migrations that touch them; a CODEOWNERS rule on migration files plus a check on table names makes this automatic. The reviewer looks at lock levels, expected duration measured on a production-like copy, and the effect on replicas.

For these changes, the pull request includes a short runbook: how to run it, what to watch, how long it should take, and what to do if it fails. It also states the rollback plan. For additive changes, rollback is usually to leave the new structure unused and roll back the code; for contract steps, it may mean restoring a dropped column from a backup, which is exactly why those steps are delayed until we are sure.

Step throughPath of a migration to production
  1. Pull request adds a migrationexpand and contract rule applies
  2. Lint the SQLdangerous operations need a safe form or a reason
  3. Test previous release against new schemaintegration tests, ddl-auto validate
  4. Does it touch a large or hot table?
    YesDatabase owner review, runbook, rollback planNoNormal code review
  5. Deploy: migration with lock_timeoutseconds, not hours
  6. Backfill job if neededthrottled, watched, resumable

6 steps in order. Play them, or step through them one at a time.

6Follow-up questions

How do you roll this out to teams without slowing them down?

Start the linter in warning mode for a few weeks to tune false positives, then make it blocking. Ship the backfill framework and CI job as shared templates so teams adopt them by changing a line of configuration. Most migrations are simple additions and pass every check automatically, so the process only slows down the rare risky ones.

What about emergency fixes?

The process keeps an emergency path: a migration can be fast-tracked with a database owner's approval, but it still runs with lock_timeout and still respects expand and contract. Emergencies are when people are most likely to drop a column too early, so the rule stays.

How do you know the process is working?

Track the number of incidents caused by schema changes, the number of linter overrides and their reasons, and deployment duration. The goal is zero migration-related downtime with hundreds of deploys per week; any incident leads to a new linter rule or test, so the process learns.

7Conclusion

In this answer, we designed a schema change process for hundreds of deploys a week. Its core is the rule that every migration works with the current and previous application versions, implemented as expand and contract with destructive steps in a later release. Automation enforces it: a linter for dangerous operations with safe alternatives, backfills as throttled jobs separate from migrations, a CI job that runs the previous release's tests against the new schema, and database owner review with runbooks and rollback plans for large tables.

What to say in the interviewAbout 90 seconds aloud

Open with

I would build the process around one rule and then automate it. The rule is that every migration must be backward compatible with the application version already running and with the version we might roll back to.

Then, if they want more

In practice that is expand and contract: add new structures first, move the code, and only drop or tighten things in a later release, never in the same release as the code that stops using them. Then automation.

Every pull request with a migration goes through a linter, for example squawk for PostgreSQL plus our own rules, that flags non-concurrent index creation, table rewrites like volatile defaults or type changes, SET NOT NULL without the check-constraint pattern, large updates and missing lock_timeout, each with a suggested safe alternative.

Long backfills are not allowed in migrations; they run as throttled, resumable jobs from a shared framework that watches replication lag. A CI job applies the new migrations and then runs the previous release's integration tests against that schema with Hibernate in validate mode, which catches premature drops and renames.

Finally, migrations touching a list of large or hot tables need a database owner's review, a duration measured on a production-like copy, a short runbook and a rollback plan. And I would track migration-related incidents and turn each one into a new check.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Define the company process for database schema changes so that hundreds of deploys per...": https://scrivio-interview-library.netlify.app/databases/schema-migration/506d089fb6/