How do you include database schema migrations in a continuous delivery pipeline without causing downtime?
What the interviewer wants to hear
- Migrations are versioned in the repo and run by a tool
- Expand and contract: backward-compatible changes first
- Old and new app versions must work with the schema during rollout
- Run migrations as a separate controlled step before deploy
- Test migrations on production-like data; watch locks on large tables
- Rollback plan: roll app back, avoid destructive down migrations
Model answer
Migrations live in the repo as versioned files, applied by a tool such as Flyway, Liquibase or the framework migrator, and every environment records which ones ran. The main rule is that during a rolling deploy both the old and new app versions run at once, so every schema change must work with both. I use expand and contract: first add new columns or tables in a backward-compatible way, deploy code that writes to both or reads the new one, backfill in batches, and only drop the old structure in a later release. In the pipeline the migration runs as its own step, for example a Kubernetes Job or Argo CD PreSync hook, before the new pods start, and the deploy stops if it fails. I test migrations against a copy of production-sized data to catch long locks, and use online index creation. Rollback means rolling back the app, not running destructive down migrations.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium DevOps Engineer questions
- How do you manage secrets such as database passwords and API keys across CI/CD pipelines and Kubernetes?
- A Pod is stuck in CrashLoopBackOff after a deployment. How do you troubleshoot it?
- Compare rolling, blue-green and canary deployments. How do you decide which to use?
- Developers complain that the CI pipeline takes 40 minutes. How would you make it faster?
- How do you structure Terraform code for multiple environments like dev, staging and production?
- Your team is burning out from on-call pages. How would you redesign alerting and the on-call process?
- When would you package Kubernetes manifests with Helm and when with Kustomize? Can they be combined?
- Users report that one service on Kubernetes became slow since this morning. Walk me through how you would investigate.
- How would you promote a release from dev to staging to production in a GitOps setup with Argo CD?