What you'll learn: By the end of this lesson you will be able to describe blue-green and canary releases for a static or server-rendered front end, say where the "pointer" that selects a build lives, split traffic in a way that keeps one user on one version, choose the signals that promote, hold or roll back a canary, explain version skew and the open-tab problem, and list what a rollback does not restore: configuration, persisted browser data, back-end changes and the next automatic deploy.
Think of a restaurant introducing a new recipe. Serving it to every table at once is a gamble. Serving it to one table, watching the plates come back, and then to a few more is a canary. Keeping the old kitchen ready behind a door and swapping doors when the new one passes its tasting is blue-green. Either way you need a way back, and diners already seated are still eating the old dish.
The running example is the ShopStream storefront checkout, a React page that adds a delivery-slot step. The previous lesson, CI/CD for Front Ends, ends with a pipeline that builds one artifact and releases it assets first, HTML last. This lesson covers what happens next.
The core idea
- A release is a pointer move. Users get whichever build the entry point (the HTML, or the alias or traffic rule in front of it) names. Blue-green moves all traffic between two complete environments at once; a canary moves a slice and widens it.
- Two versions always coexist. The pointer is read when a page loads. Tabs already open keep running the old code and calling your servers.
- A rollback restores code, not the world. It does not undo configuration, data the new version wrote in the browser, back-end changes or a pipeline that deploys again an hour later.
The patterns
Martin Fowler describes blue-green deployment as two production environments "as identical as possible", one live and one idle. Test the idle one, then switch the router; the previous environment stays intact, so rolling back means switching back. His canary article describes routing a few users to the new version and widening as confidence grows; rollback is rerouting users to the old version. A canary is not an A/B test: an A/B test can take days to reach significance, a canary should finish in minutes or hours.
| Pattern | What moves | Who sees the new version | Rollback | Main cost |
|---|---|---|---|---|
| Blue-green | All traffic, at once | Everyone, after the switch | Switch back | Two full environments; a big-bang exposure |
| Canary | A growing share | A small group first | Reroute to the old version | Two versions live; needs good signals |
| Feature flag | Behaviour inside one build | Whoever the flag targets | Turn the flag off | Flag debt; covered in the feature-flag lessons |
Where the pointer lives
On a front end the pointer is rarely a load balancer you run. Which place it sits in decides what a rollback costs.
Figure 1. Where the release pointer can sit
How to read this: the entry point picks a build per request or per visitor. Both builds call the same APIs, so back-end compatibility is a requirement of the release, not a detail.
Documented examples, as at the time of writing (check the current pages before relying on them):
| Mechanism | What the documentation says |
|---|---|
| Platform alias | Vercel's Instant Rollback points domains back to a previous production deployment; only deployments previously aliased to production are eligible. |
| Atomic deploys | Netlify: no change goes live until all are uploaded; a rollback publishes a previous atomic deploy without a new deploy. |
| Percentage split | Cloudflare Workers gradual deployments route a percentage of requests to the new version, the rest to the previous one. |
| Staging distribution | CloudFront continuous deployment sends a weighted share of production requests, or requests with a given header, to a staging distribution. |
Canary for a front end
Choosing who gets the new build
Fowler lists a random sample, employees first, users picked by profile, or a region. For a front end add one rule: keep each visitor on one version. Cloudflare's documentation says that by default each request is routed independently by the configured percentages, so one user's requests may reach different versions, and that version affinity sends requests with the same key to the same version. CloudFront's weight-based configuration offers cookie session stickiness with an idle duration from 300 to 3600 seconds, and a header-based configuration (the header must start with aws-cf-cd-) that suits staff testing.
Without stickiness, a page's HTML can come from one build and its script request from the other, which works only if each build's hashed files exist for both.
Illustration 1: the minimal example
A stable bucket from a user id and a release name, so the same user always lands on the same side and widening the percentage only adds users. Run in Node (letters: n for the new build, o for the old):
import { createHash } from "node:crypto";
function bucket(userId, release) {
const digest = createHash("sha256").update(`${release}:${userId}`).digest();
return digest.readUInt32BE(0) % 100;
}
function version(userId, release, percent) {
return bucket(userId, release) < percent ? "new" : "old";
}
const users = Array.from({ length: 10 }, (_, i) => `user-${i + 1}`);
for (const percent of [10, 50]) {
const row = users.map((u) => version(u, "checkout-v2", percent)[0]).join("");
console.log(`${String(percent).padStart(3)}% ->`, row);
}
const again = users.map((u) => version(u, "checkout-v2", 10)[0]).join("");
console.log("10% again ->", again);
let inNew = 0;
const total = 10000;
for (let i = 0; i < total; i++) if (version(`user-${i}`, "checkout-v2", 10) === "new") inNew++;
console.log(`share in new at 10% over ${total} ids:`, (inNew / total * 100).toFixed(1) + "%");
Output, from running it in Node 26.13.1:
10% -> onnooooooo
50% -> onnnonnono
10% again -> onnooooooo
share in new at 10% over 10000 ids: 10.3%
Each user new at 10% is also new at 50%, the repeat run gives the same answer, and over 10,000 ids about a tenth land in the new build (ten users are too few to show the share). This is a teaching model: a CDN or platform does its own assignment.
Reading the canary
A canary is only as good as what you watch. Fowler mentions monitoring business metrics and rolling back automatically on a significant regression. For the storefront, compare the canary group with the rest, by build, on JavaScript errors and failed lazy-chunk loads, Core Web Vitals from real user monitoring (see Core Web Vitals), failed API calls, and a business step such as completed checkouts. Tag every event with the build id, or you cannot separate the groups.
Figure 2. Promote, hold or roll back
(share = X%)"] --> C{"Canary vs control
on guard signals"} C -->|"clearly worse"| R["Roll back:
route all to old build"] C -->|"too little data"| H["Hold at X%
and keep watching"] C -->|"no difference"| W["Widen the share"] W --> D{"At 100%?"} D -->|"no"| S D -->|"yes"| K["Keep old build
until rollback window ends"]
How to read this: three outcomes, not two. "Hold" matters because a small share can look fine by chance. Choose the guard signals and minimum sample before the release.
Illustration 2: the realistic example
For the checkout release the team writes the plan before shipping. Percentages and waits are illustrative, not recommendations:
| Stage | Who | Hold for | Guard |
|---|---|---|---|
| 0 | Staff, by header or bucket | Until a manual pass | Checkout works end to end |
| 1 | 1% of visitors | 30 minutes | No rise in script errors or failed chunk loads |
| 2 | 10% | A few hours | Web Vitals and checkout completion match control |
| 3 | 50% | Half a day | Same, including a busy period |
| 4 | 100% | Keep build A for the rollback window | Same |
The undo is part of the plan. Not run: on Vercel, vercel promote [deployment-id or url] is the documented command that promotes a chosen deployment; on another platform it is a traffic setting. Write down the command and who may run it before the release.
Version skew and the open tab
Version skew is the mismatch that appears when dependent systems are deployed at different times. For a front end it takes two forms: an old page calling a new API, and an old page asking for a file the new deploy removed.
Figure 3. The open tab and the missing chunk
How to read this: nothing in the shopper's tab changed; the server changed under it. Keeping build A's files for a while, or pinning the tab's requests to build A, would let the chunk load.
The mitigations form a ladder:
- Keep old assets for longer than your longest session, and set
Cache-Control: no-cacheon the HTML. Vite's documentation says that after a deployment a visitor may run outdated code that requests deleted chunks, and thatno-cacheon the HTML stops old assets staying referenced. - Recover on a load error. Vite emits
vite:preloadErrorwhen a dynamic import fails;event.payloadholds the original error, andevent.preventDefault()stops the error being thrown. Its documented example reloads the page. - Lock the version. Vercel's Skew Protection pins framework-managed requests (assets, client navigations, prefetches) to the deployment that served the page. It does not pin full-page navigations, which get the latest deployment. Its maximum age defaults to 12 hours on Pro and one day on Enterprise.
- Make the API tolerant. The skew article advises that servers never introduce new required fields until all clients are updated, that clients never require recently introduced server changes, and that teams define a rollback window (API Contract Evolution for Clients).
The same article calls HTML skew so hard to reason about that the reliable approach is to make sure it never happens.
Illustration 3: a failure, and a guard
The delivery step is lazy-loaded, so after a deploy that deleted build A's files it fails on tabs opened earlier. A reload recovers, but a reload loop is its own failure when the chunk is missing for another reason. This sketch reloads once per tab session. Not run:
window.addEventListener("vite:preloadError", (event) => {
if (sessionStorage.getItem("reloaded-for-chunk") === "1") return; // let the error surface
sessionStorage.setItem("reloaded-for-chunk", "1");
event.preventDefault();
window.location.reload();
});
The flag must be cleared after a successful load, or a second deploy in the same session will not recover. Reloading also discards unsaved input, so for a checkout prefer keeping old assets or pinning over reloading mid-flow.
What a rollback does not restore
Rolling back moves the pointer. It leaves several things where they are.
- Configuration. Vercel's documentation says a rollback does not update environment variables changed in project settings, and the rolled-back deployment's configuration may be stale.
- The next deploy. After a Vercel rollback, auto-assignment of production domains is turned off, so new pushes do not go live until a deployment is promoted. Netlify says that with auto publishing on, a new Git-triggered production deploy overwrites a rolled-back version; locking deploys pauses publishing.
- The old build itself. Netlify deletes deploys after 30 days (90 on paid plans) by default, except the published one and a few recent ones. Keep artifacts longer than the window in which you might roll back.
- Data in the browser. If build B wrote a new shape to local storage or IndexedDB, build A must tolerate it (State Persistence and Synchronization, Browser Storage Options).
- Back-end and database changes. Fowler's advice: separate schema changes from application upgrades, make the schema work for both versions, deploy the app, remove old support later. See Schema Evolution and Zero-Downtime Migrations.
- Other caches. A service worker can keep a client on the old shell (Service Worker Lifecycle and Updates), and the CDN can hold the previous HTML (CDN and Edge Caching).
Trade-offs
| Choice | Gain | Cost |
|---|---|---|
| Blue-green | Instant switch and switch back | Everyone is exposed at once; two environments to keep identical |
| Canary | Real-user evidence before full exposure | Two versions in production; needs tagging, stickiness and judgement |
| Sticky assignment | One visitor sees one version | Cookie or key handling; uneven shares |
| Keeping old assets | Open tabs keep working | Storage, and old code stays reachable |
| Reload on chunk failure | Self-healing | Lost unsaved input; a loop if the cause differs |
Build it
This lesson has no lab: traffic splitting is a hosting platform's service. The bucketing snippet was run and its output is shown unedited; the reload guard and the platform command were not run, and nothing was exercised against a real CDN or hosting platform.
The other side of this topic
The back-end view covers deploying services: rolling, blue-green and canary across instances, health checks and database compatibility, in the back-end lesson on deployment strategies. This lesson stays with code that runs in other people's browsers and cannot be restarted.
In practice: the delivery-slot checkout
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
The checkout gains a delivery-slot step that reads a new field from the cart API. Releases are all-at-once: the pipeline replaces the live files, and the last rollback meant redeploying the previous commit, which took 20 minutes (illustrative).
Starting architecture
Figure 4. All-at-once release
How to read this: one live build is overwritten, so there is no second build to switch to and no slice to watch.
Options considered
| Option | What it fixes | Risk |
|---|---|---|
| Blue-green on the platform alias | Instant rollback | A defect hits all users first |
| Canary with sticky buckets | Evidence before full exposure | Thin data at small shares |
| Feature flag for the new step | Turn it off without a deploy | Flag left on forever |
The decision
| Field | Decision record |
|---|---|
| Context | An all-at-once release replaces files in place, and a rollback is a rebuild. |
| Decision | Keep every release as its own deployment. Release through a sticky canary, staff first, using the plan in Illustration 2. Keep the previous build and its assets until the rollback window ends. Make the cart API accept requests with and without the new field before the front end uses it. |
| Consequences, good | Problems show on a small share; rollback is a pointer move. |
| Consequences, bad | Two builds live for hours; a dashboard split by build id to maintain. |
| Revisit when | A feature flag can carry the step, or sessions grow long enough to need version locking. |
Rollout and verification
- Deploy the API change first and check that old and new front-end requests both succeed.
- Tag events with the build id and confirm the dashboard can filter by it before any traffic moves.
- Rehearse the rollback on a preview: move the pointer, load an old tab, open the lazy step.
- Run stages 0 to 4, holding when data is thin, with the rollback owner named.
The 2 a.m. failure
At the 10% stage errors rise on the new build and the on-call engineer uses the platform's rollback; the error rate falls. Hours later a developer merges the fix. The pipeline reports success, but the live site does not change.
On a platform that behaves like Vercel's Instant Rollback, a rollback turns off automatic assignment of production domains, so new pushes do not go live until someone promotes a deployment. First three checks: (1) is production in a rolled-back state; (2) does the live build id match the latest successful deployment; (3) does the runbook name an "undo the rollback" step. Mitigation: promote the fixed deployment. Follow-up: add that step to the runbook and show the rolled-back state on the release dashboard.
Architect's notes
- Write the rollback before the release: who may run it and how you will know it worked.
- Plan for two versions at once. Compatibility with old tabs is the requirement, whatever the pattern.
- Tag everything with the build id, or a canary cannot be read.
- Pick guard signals and sample sizes in advance, not after seeing the graph.
- A rollback is also a deploy, with the same care about caches, config and automation.
Common mistakes
- Deleting the previous build's files in the same release.
- No stickiness, so one visitor's HTML and scripts come from different builds.
- Judging a canary on averages that hide a small affected group.
- No build id on errors.
- Forgetting the rollback state that blocks the next automatic deploy.
- Rolling back the front end after the API moved on incompatibly.
- Reload-on-error without a guard, which loops.
Key takeaways
- A release moves a pointer; blue-green moves all traffic between two environments, a canary moves a growing share.
- Keep a visitor on one version, and tag all signals with the build.
- Open tabs mean two versions always coexist; keep old assets, serve HTML with
no-cache, and consider version locking. - Promote, hold or roll back on pre-agreed guard signals.
- A rollback restores code only; handle configuration, browser data, the API and automatic deploys separately.
- Keep old artifacts longer than the window in which you might roll back.
Practice exercises
Exercise 1: Starter (30 min). Run the bucketing snippet with another release name and describe what changes when you raise the percentage.
Exercise 2: Intermediate (2 hours). Write a canary plan for a page you know: stages, who, how long, guard signals, the rollback command and the minimum sample before widening.
Exercise 3: Advanced (half day). List every place a client could still run build A after a rollback (open tab, service worker, CDN HTML, local storage) and what each needs to be safe.
Related reading
In this course:
- CI/CD for Front Ends: the pipeline that produces the artifacts this lesson releases.
- CDN and Edge Caching: why hashed assets and uncacheable HTML make switching builds safe.
- Service Worker Lifecycle and Updates: the client-side cache that can outlive a rollback.
- Real User Monitoring: the signals a canary reads.
- API Contract Evolution for Clients: keeping old front ends working against new APIs.
Official documentation
- Martin Fowler: BlueGreenDeployment and CanaryRelease: the two patterns.
- Vercel: Instant Rollback and Skew Protection: rollback behaviour and version locking.
- Netlify: Manage deploys: publishing a previous deploy, locked deploys, retention.
- Cloudflare: Gradual deployments: percentage splits and version affinity.
- Amazon CloudFront: Continuous deployment: weighted and header-based routing.
- Vite: Building for production: load error handling after a deploy.