Safe deployments and rollback
Why releasing gradually matters
Deployment changes software in an environment; release makes functionality available to users. These may happen at the same time or be separated by feature flags. A rollout is the process of moving from an old version to a new one. Use the same verified artifact from staging and check target-specific configuration before admitting traffic. Start with a clear recovery plan and known healthy baseline. A deployment that completes is not necessarily a release that meets user-facing reliability goals.
Choose a rollout strategy
A rolling update replaces instances in batches. It can reduce downtime but old and new versions may coexist, so APIs and data formats must be compatible. Blue-green deployment prepares a separate environment and switches traffic; it can simplify switching back, but duplicated capacity and shared databases complicate cost and recovery. A canary exposes a limited fraction of traffic or users to the new release before expanding. It requires a measurable comparison and traffic controls. Feature flags can separate deployment from feature exposure, but flags require cleanup and do not reverse data changes.
Provider examples include target-specific canary support in Google Cloud Deploy, cloud deployment actions orchestrated by AWS CodePipeline, and controlled environment stages in Azure Pipelines or GitHub Actions. Check the actual target and integration before selecting a strategy; an approval gate alone does not implement a canary.
Worked example: compare the new version fairly
A fictional bookstore receives 2,000 requests during a 10% canary stage. Under the simplified assumption that the router distributes exactly the configured share, 200 reach the canary and 1,800 reach the stable version. The canary returns 8 errors (4%); stable returns 9 errors (0.5%). An overall error rate of 17/2,000 = 0.85% hides the canary problem. Compare metrics by release version, with the same time window and similar traffic types. Real routing fractions may vary with session affinity, traffic volume and request mix.
A teaching policy requires at least 100 canary requests, readiness, authorization and at most 2% errors before advancing one stage. Eight errors out of 200 exceed the threshold. Pause new promotion and initiate rollback review. Zero errors in 20 requests does not meet the minimum sample. The threshold is fictional, not a production standard; real gates need statistical judgment, latency, saturation, business outcomes and time bounds.
Run the offline rollout decision model
The Python example below is standalone and uses no files, network or credentials. It models a single decision using a deliberately small policy. Inputs are integer counts and Boolean readiness and approval. It does not call a deployment API, check real telemetry, perform rollback or prove safety. rollback review asks an authorized operator or separately verified automation to evaluate recovery. Missing authorization or readiness blocks advancement even if an error sample exists.
def rollout_decision(requests, errors, ready, approved): if requests < 0 or errors < 0 or errors > requests: return "invalid" if not approved or not ready: return "pause" if requests < 100: return "pause" # Compare exact integers: error rate greater than 2%. if errors * 100 > requests * 2: return "rollback review" return "advance one stage"
for sample in [(200, 3, True, True), (200, 8, True, True), (20, 0, True, True), (200, 0, False, True)]: print(rollout_decision(*sample))Expected output:
advance one stagerollback reviewpausepauseThe first sample has 1.5% errors, the second has 4%, the third lacks evidence and the fourth is not ready. Integer comparison avoids floating-point boundary surprises at exactly 2%. Invalid counts are rejected. In real systems a bad metric can trigger incident handling even when a release is paused; the toy function intentionally does not model that separate alarm path.
Rollback, roll-forward and data compatibility
Rollback restores a known previously working application version or traffic assignment, after confirming the old artifact, configuration and dependencies remain usable. Roll-forward applies a new correction when going back is unsafe or slower. Neither guarantees restoration of database contents. If a new version removed a database column, the old application may no longer run. Use compatible schema evolution: add a new field first, deploy code that tolerates both forms, migrate and verify data, and remove the old field only after the rollback window closes. Backups and tested restore procedures are separate recovery controls.
For a failed canary, stop expanding, retain evidence, verify that stable capacity can accept the returned traffic, confirm data compatibility, switch traffic back using an authorized change, and test the user flow and metrics. If rollback is unsafe, isolate the failing feature or choose a reviewed forward fix. Keep a record of the artifact and recovery result. Avoid blindly retrying deployments or overwriting incident evidence.
Design a promotion checklist and observe cost
Before promotion, verify artifact identity, provenance, tests, target and configuration, permission scope, approvals, data compatibility, health checks, metric coverage, capacity, budget, recovery owner and previous known-good artifact. During promotion, observe error rates, latency, traffic share, resource saturation and user-visible outcomes. After promotion, continue monitoring for a defined observation window and record results. An approval is not a substitute for live checks.
A fictional blue-green release uses two additional instances for 3 hours at $0.10 per instance-hour, so extra compute costs $0.60, excluding storage, load balancing and data transfer. Retaining both environments longer increases cost. Never treat budget alerts as an immediate hard stop. Choose a strategy based on outage tolerance, traffic volume, state compatibility, platform capability, team experience and recovery needs.
Practice and next step
Given a staging-approved artifact and a 10% canary that fails its error threshold, explain why rebuilding the artifact is not a rollback. Specify which metrics must be inspected, who can approve a recovery, how to check old-version compatibility and how to prove that users recovered. Repeat with too few requests and with a destructive schema change. Next: IAM and identity federation across clouds, where the trust policies introduced here are explored in more depth.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Safe deployments and rollback — knowledge check
Choose the best answer for each offline scenario.
A canary returns 8 errors from 200 requests; the limit is 2%. What is its error rate?
What should the toy gate do with 20 successful requests and a required minimum of 100?
Which rollout prepares a second environment and then switches traffic?
Why may a previous application version fail after a rollback?
What evidence should confirm recovery?