How do you handle database migrations safely within a deployment pipeline?
CI/CD & GitOps · Advanced level
Answer
Database migrations should be backward-compatible, observable, and separated from risky application rollout when needed. I prefer expand-contract patterns, pre-deploy additive changes, app deploy, validation, and later cleanup. The pipeline should block irreversible changes without explicit approval.
Technical explanation
Safe release design assumes rollback may be needed and separates code deployment, data changes, and user exposure.
Compatibility windows and observability are mandatory when application and database versions overlap.
A secure pipeline protects source, build environment, dependencies, artifacts, deployment credentials, and runtime promotion gates as one chain.
Immutable artifacts, SBOMs, signatures, provenance, vulnerability gates, and environment promotion reduce ambiguity about what was built and deployed.
CI runners are high-value targets; isolate untrusted jobs, patch runner images, remove persistent credentials, and prefer ephemeral execution where possible.
Release safety depends on both automation and observability: use canaries, feature flags, rollback plans, and automated metric-based decisions.
Hands-on example
1. Design an advanced delivery exercise for: How do you handle database migrations safely within a deployment pipeline using one service, one Git repository, one artifact registry, and one Kubernetes environment.
2. Implement an expand-contract migration: add nullable column/table first, deploy app compatible with old and new schema, backfill safely, then remove old schema in a later release.
3. Run the migration in a staging clone, measure duration and locks, add a pre-deploy backup checkpoint, and define a forward-fix plan for non-reversible steps.
4. Use progressive exposure where relevant: feature flag off by default, canary 5%, automated metric check for error rate and latency, then expand or rollback.
5. Record audit evidence: PR, approver, pipeline run, artifact digest, SBOM location, signature verification result, deployment event, and rollback or forward-fix decision.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More CI/CD & GitOps interview questions
- How would you integrate SAST and dependency scanning into a pipeline?
- How do you implement feature flags, and how do they decouple deploy from release?
- How do you implement secrets scanning to prevent credentials in commits?
- What is the difference between deployment and release?
- Why should the same artifact move through environments rather than rebuilding per stage?
- How do you ensure a pipeline is fast enough to give quick feedback?
- What is artifact promotion, and why not rebuild between environments?
- How would you design a pipeline for a microservices architecture?