Full answer
Deploy strategies
- Rolling. Replace instances a few at a time; the load balancer stops sending traffic to an instance (draining in-flight requests) before it restarts. Cheap, but old and new versions serve traffic together for a while, and a rollback is another rolling deploy.
- Blue-green. Run the new version (green) next to the old (blue), test it, then switch all traffic at the load balancer or DNS. Instant rollback by switching back. Costs double capacity during the switch.
- Canary. Send 1%, then 10%, then 50% of traffic to the new version, comparing error rates and latency with the old one automatically. Stop and roll back if metrics worsen. The safest for large services.
- Feature flags separate deploying code from releasing features, so risky behaviour is turned on gradually after the deploy.
Requirements for all: health checks that reflect real readiness, graceful shutdown, and backward-compatible APIs between services (a new client may talk to an old server and the other way round).
Schema changes: expand and contract
Example: rename users.fullname to users.display_name.
- Expand. Add
display_nameas a nullable column. Old code ignores it. (On large tables, use online schema change tools or database features that avoid long locks.) - Dual write. Deploy code that writes both columns and reads
display_namewhen present, falling back tofullname. - Backfill. Copy
fullnameintodisplay_namein small batches to avoid locking and replication lag. - Switch reads. Deploy code that reads only
display_name(still writing both, for rollback safety). - Contract. After a safe period, stop writing
fullname, then drop the column.
Each step is a separate deploy and can be rolled back without data loss, because at every point both old and new code can run against the schema.
Dangerous changes
- Adding a
NOT NULLcolumn without a default, or adding an index without the online option, can lock a large table. - Dropping or renaming a column in the same deploy as the code change breaks the instances still running old code.
- Changing an enum or a message format that other services read; version messages and accept both formats during the transition.
Checklist
Automated migrations run before the code that needs them, migrations are backward compatible, long backfills are throttled and resumable, and dashboards are watched during each step.
By level
Fresher: Explain that servers are updated a few at a time so users never see the site go down. A fresher should know why removing a column early breaks old servers.
Mid: Compare rolling, blue-green and canary deploys, and walk through expand and contract with a backfill. Mention feature flags.
Senior: Discuss online schema change tools, large backfills, cross-service compatibility, mobile client lag and automated canary analysis. Expect a reversible plan at every step.
Key points
- Rolling, blue-green and canary trade cost against rollback speed and safety
- Old and new code run together, so changes must be compatible
- Expand, dual write, backfill, switch reads, contract
- Backfill in small throttled batches
- Every step separately deployable and reversible
Common mistakes
- Renaming or dropping a column in the same release as the code change
- Long locking migrations on large tables
- Canary releases without automatic metric comparison
- No graceful shutdown, so in-flight requests fail during deploys
Follow-ups
- How would you split one table into two with zero downtime?
- How do you handle a migration on a 2 TB table?
- How do mobile apps that update slowly affect API changes?
Tips
- Use the column rename example
- Say clearly that both versions run at once
- Pair canaries with automated rollback
Evaluation rubric
- Correct deploy strategies and trade-offs
- Expand-and-contract explained step by step
- Identifies dangerous migrations
- Rollback and compatibility reasoning