Deployment strategies
Move from a laptop shell to a safe, observable delivery pipeline: version control, Linux processes and permissions, container images, networking, configuration and secrets, deployment, health checks, observability, rollback, reproducibility and security hardening.
What you will be able to do
#- Compare rolling, blue-green and canary deployments.
- Explain immutability and why rebuilding in place is risky.
- Plan a database migration that is safe to deploy alongside code.
Overview
#Deployment is the act of moving a built artifact into serving position. The strategy you choose decides how much risk you take on and how quickly you can back out.
Strategies
- Rolling: replace instances a few at a time. Cheap, but old and new versions run side by side during the rollout.
- Blue-green: stand up a full new environment, switch traffic, keep the old one for instant rollback. Costs double capacity during the switch.
- Canary: send a small fraction of traffic to the new version, watch metrics, then widen. Catches problems on real traffic with limited blast radius.
canary: 5% -> 25% -> 50% -> 100% (advance only if error rate and latency hold)
Immutability
Build the artifact once, promote that exact artifact through environments, and never patch a running server. Immutable deploys make rollback a matter of pointing at the previous artifact.
Database migrations
Code and schema change at different speeds. Use expand-and-contract: add the new column (expand), deploy code that writes both and reads the new, then remove the old column (contract) in a later deploy. A destructive migration in the same deploy as the code that depends on it cannot be rolled back safely.
Common pitfalls
- Rebuilding the artifact per environment, so production runs code that was never tested.
- A migration that drops a column the old version still reads, breaking rollback.
- Advancing a canary on time rather than on metrics.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Predict
A canary is at 5% of traffic and the new version's error rate is 4x the baseline, but latency is fine. What should happen next?
Read the code, then choose the best answer. The reference explanation stays hidden until you respond. stimulus.txtcanary: 5% | error_rate: 4x baseline | latency: normalExercise 2Implement
Write the ordered steps of an expand-and-contract migration that renames a column users.name to users.full_name without breaking the running old version.
starter.text# expand, migrate, contractReveal the reference answer
reference.text1. Expand: add the new column full_name (nullable). 2. Deploy code that writes both name and full_name and reads full_name with a fallback to name. 3. Backfill full_name from name for existing rows. 4. Once all instances run the new code, stop writing name and read only full_name. 5. Contract: drop the old name column in a later deploy.Authored expected output: A five-step plan where the old column is removed only after no running instance depends on it.
Each step is independently deployable and reversible until the final contract step. This keeps rollback possible at every intermediate point.
Exercise 3Interview
Your team deploys a web API several times a day and wants to reduce the blast radius of a bad release while keeping rollback fast. Which strategy would you propose and why?
starter.text// Propose a strategy with trade-offs.Reveal the reference answer
reference.textPropose canary releases for gradual exposure with metric guardrails, combined with immutable artifacts so rollback is a pointer change. Blue-green gives the fastest, most certain rollback but needs double capacity; rolling is cheapest but exposes old and new versions together. A reasonable answer names the trade-off between capacity cost, rollback speed and exposure, and picks a strategy that matches the team's monitoring maturity.Authored expected output: A justified recommendation that names capacity, rollback speed and exposure trade-offs.
There is no single correct strategy. A strong answer shows the trade-off reasoning and ties the choice to the team's ability to detect a bad release.
Common misconceptions
#- Blue-green means no downtime at any cost: it needs double capacity during the switch.
- A rollback always undoes a migration: schema changes often cannot be reversed automatically.
Follow-up practice
#- devops-health-checks
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.