Rollback and release safety
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
#- Choose between rollback and roll-forward for a bad release.
- Use feature flags to decouple deploy from release.
- Write a rollback runbook and verify it works before you need it.
Overview
#A release is not done until you can undo it. Rollback returns to the previous known-good state; roll-forward ships a fix. Which is right depends on how fast you can detect and fix the problem and whether the change is reversible.
Rollback versus roll-forward
Roll back when the previous artifact is known good and the failure is clear. Roll forward when the change is a data migration that cannot be reversed, or when the fix is trivial and faster than a rollback cycle. Decide in advance, not during the incident.
Feature flags
A flag decouples deploying code from releasing a feature. Deploy with the flag off, enable it for a small group, then everyone. If it misbehaves, turn the flag off instantly without a deploy.
if (flags.isEnabled('new_checkout', { userId })) {
return newCheckout(req);
}
return legacyCheckout(req);
Flags are not free: each one is a branch to test and eventually remove. Track them and delete stale flags.
Runbooks
A rollback runbook lists the exact commands, the checks after rollback, and the owner. Test it in staging on a normal day so it is not the first time you run it during an incident.
Common pitfalls
- Discovering during an incident that the previous artifact is no longer available.
- A migration that cannot be reversed, so rollback leaves the schema ahead of the code.
- Flags that are never removed, accumulating dead branches and confusion.
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 1Interview
A release added a column and the code now reads it, but the migration also dropped an old column. Error rates spike. Walk through your rollback decision.
starter.text// Decide rollback vs roll-forward and justify.Reveal the reference answer
reference.textRollback is unsafe because the previous code reads the dropped column, so reverting the artifact would fail. The safer path is roll-forward: ship a fix that restores compatibility, or apply an expand-and-contract correction that re-adds the column as a compatibility shim. The lesson is that the destructive migration should never have shipped in the same release as the code depending on it.Authored expected output: A justified roll-forward decision that explains why rollback would break.
When the schema moved ahead of the previous code, rollback breaks the old code. The answer must recognize the irreversibility and choose roll-forward.
Exercise 2Implement
Write a feature flag check with a kill switch: the new path runs only when the flag is enabled for the user, and a global off switch disables it for everyone immediately.
starter.javascript// flag check with global kill switchReveal the reference answer
reference.javascriptfunction useNewCheckout(userId) { if (!flags.isEnabled('new_checkout_global')) return false; return flags.isEnabled('new_checkout', { userId }); } // in the handler return useNewCheckout(req.user.id) ? newCheckout(req) : legacyCheckout(req);Authored expected output: New path only for flagged users; turning off the global flag reverts everyone without a deploy.
Two levels let you disable everything instantly while still rolling out gradually per user. The global switch is the incident kill switch.
Exercise 3Debug
During an incident the team tries to roll back but the previous image tag was overwritten by the new build, and the database migration already ran. What two process failures does this reveal?
starter.text# image tag: app:latest overwritten; migration appliedReveal the reference answer
reference.textFirst, using a mutable tag means the previous artifact is gone; every deploy must produce an immutable, retained artifact so rollback has a target. Second, running an irreversible migration without a reversible plan removes the rollback path; migrations must be expand-and-contract and backward compatible with the previous code.Authored expected output: Two fixes: immutable retained artifacts, and reversible backward-compatible migrations.
Rollback is only possible if the old artifact still exists and the schema still works with the old code. Both must be designed in before the incident.
Common misconceptions
#- Rollback is always the right first move: an irreversible migration makes roll-forward safer.
- Feature flags are permanent: they add test surface and must be cleaned up.
Follow-up practice
#- devops-reproducibility
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.