CI/CD for developers · senior
Safe releases: strategies, flags and database migrations
Your code and database must work while two versions run together. Choose rolling, blue-green or canary on purpose, separate deploy from release with feature flags, and make migrations backward compatible.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Rolling: both versions serve for minutes. APIs must work for clients that hit new then old. Events must be readable by both (consumers ignore unknown fields, producers do not remove fields). The schema must suit both: expand, migrate, then contract later. Changed cache formats need new keys.
- Blue-green: a full second environment and a switch at the load balancer. Instant switch back, but double cost while both run, the shared database still needs both versions to work, and green must be warmed and long connections drained.
- Canary: a small share of traffic goes to the new version (Argo Rollouts, Flagger, weighted targets), with automatic checks on error rate and latency and automatic rollback.
- Feature flags separate deploy from release. Deploy days before a freeze with the flag off, release by turning it on. Evaluate flags on the server with an SDK that caches rules, and use a safe default (off) when the flag service is unreachable.
- Targeting: staff and test accounts first, then a percentage by a stable hash of the user id so each user sees one version, then everyone. Watch metrics split by flag variant. The kill switch turns it off in seconds. Remove old flags.
- Migrations: even an instant ADD COLUMN needs an exclusive metadata lock for a moment. A long-open transaction holds a shared lock, so the ALTER waits, and every new query on the table queues behind it. The whole table freezes. Look at the process list, metadata locks and open transactions, and kill the old transaction or the ALTER.
- Prevent it: set a lock timeout for migrations, avoid long transactions, run migrations as one Job and not at startup of every pod (many pods race, fail startup probes and restart), and use expand and contract in separate releases.
- Rollback plan: the old version must work with the new schema, so never drop or rename a column in the same release as the code that stops using it.
The red pen
Common traps: mistake → fix
Mistake: Blue-green makes the database switch easy
Fix: Both versions use the same database, so it must support both.
Mistake: A feature flag removes the need to test
Fix: It reduces release risk but does not replace tests, and old flags become debt.
Mistake: An instant ALTER cannot block anything
Fix: It still needs a lock and can queue behind an old transaction.
Easy to hard
Questions interviewers ask, easy to hard
- Compare rolling, blue-green and canary releases.
- What must your code survive during a rolling deploy?
- How would you release a big feature on a deploy-freeze day?
- A migration locked the orders table in the middle of a deploy. Explain how and what you do.
- What is expand and contract?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.