Release strategies and rollback — study guide

The concept's fragments, read in order.

For your capstone Take your own app to production

Your app ships to people who did not volunteer to test it, and the release strategy decides what a losing release costs: how many of them meet it, and how quickly you get back. Two things carry that weight, the image reference your deploy names and the schema your database holds. When a release goes bad anyway, incident response is where this way back gets used.

Say app:2.14.0 goes out on a rolling update and its p95 climbs past your 300 ms target. Because every deploy names an image by unique version, going back is redeploying app:2.13.2, a reference you already trust. That works only because 2.14.0 added full_name beside name instead of renaming the column: the old version still finds the column it asks for. Rename it in place and the rollback lands old code on a schema it cannot use.

Shipping a change you can take back

Every release is a bet that the new version is better than the one it replaces. Most bets win, some lose, and no amount of testing gets the losing ones to zero, because production has real users, real data, and real traffic that no test environment fully reproduces. A release strategy does not try to make every bet a winner. It makes losing one cheap: few users hurt, for a short time, with a quick and boring way back.

Two words carry most of the idea. Deploying puts new code into production, running. Releasing makes its new behavior available to users. They usually happen at the same moment, but they do not have to, and pulling them apart is one of the strongest levers you have: code that is deployed but not yet released can be switched on gradually, and switched off again, without another deploy.

The rest of this concept covers the main ways to ship a change: rolling updates that replace copies a few at a time, blue-green deployments that flip between two complete environments, canary releases that let a small slice of traffic go first, and feature flags that separate the deploy from the release. Then the two ways out of a bad release, rolling back and rolling forward, and the one part of your app that does not roll back with the code: the database.

Replacing copies a few at a time

a rolling update: replace a few copies at a time before router requests v1 v1 v1 v1 every request goes to the old version batch 1 router requests v1 v1 v1 v1 v2 starting an extra new copy starts; it gets no requests until its health check passes batch 2 router requests v2 v2 v1 v1 old and new versions serve requests at the same moment after router requests v2 v2 v2 v2 rolling back is the same walk, from v2 back to v1
A rolling update replaces four copies of an app one batch at a time: an extra new copy starts first and takes requests only after its health check passes, and in the middle of the update old and new versions serve requests at the same moment.

The bluntest way to ship is to recreate: stop every copy of the old version, then start the new one. It is simple and it guarantees only one version ever runs, but there is a gap in between where nothing answers requests, and if the new version will not start, the gap does not close on its own.

A rolling update avoids the gap by replacing copies in batches. Suppose, for this example, your app runs as four containers behind a router. The update starts a new-version container, waits until its health check says it can actually serve requests, lets the router send it traffic, and only then retires an old one, repeating until every copy is new. The health check is the gate that matters: a new copy that is marked ready before the app inside it can handle a request gets traffic it will fail. Orchestrators expose how fast this goes as settings; Kubernetes, for example, by default allows up to 25 percent extra copies above the desired count and up to 25 percent unavailable while a rollout is in progress. With those defaults an old copy can be stopped before its replacement is ready; to get the strict start-then-retire order described here, you set the unavailable allowance to zero.

The catch is in the middle of the update. For a while, old and new versions are both serving, and any given request may land on either one. So the two versions have to get along: the same API shapes, data formats both can read, and a database schema both can use. A change that only works if every copy switches at the same instant is not safe to roll.

Undoing a rolling update is another rolling update, back to the previous image. That is reliable but not instant: the way back walks through the same batches as the way forward, and the bad version keeps serving a share of requests until it is replaced.

Two environments and a switch

two full environments, one switch users requests router blue: old version v1 still running, no traffic green: new version v2 live, takes every request all traffic after the switch rollback: switch back database one, shared reads, writes reads, writes the switch moves requests, not data: what v2 wrote is still there after a switch back
Blue-green deployment: the router sends all traffic to the green environment running the new version while the blue environment with the old version keeps running idle, so rolling back is switching the router back; both environments use one shared database, which the switch does not undo.

Blue-green deployment runs two complete production environments side by side. One, call it blue, is live and serving users. The new version goes into the other, green, where it can be started, health-checked, and tested against production configuration while no user touches it. When green looks right, the router or load balancer in front of them moves traffic from blue to green, usually all at once.

The point of the design is the way back. Blue is still running the old version, untouched, so rolling back is moving the traffic back like throwing a set of railway points: both tracks are already laid, the switch sends every train down one of them, and throwing it back is instant because the other track was never torn up. Nothing has to be rebuilt or restarted; the old version is already warm and waiting. That only holds while blue is kept running; tear it down the moment green goes live and the cheap rollback goes with it.

Two costs come with it. Both environments must be able to carry production load, so for the length of the release you are paying for roughly twice the capacity. And the cutover is all-or-nothing: if green is broken in a way the checks missed, every user meets it at once until someone switches back.

The bigger limit is the database. Your app has one relational database, and blue and green usually share it, because giving each its own copy means keeping the two in sync, which is its own hard and risky problem. The switch moves requests, not data. Whatever green wrote while it was live is still there after a switch back, so the schema and the data have to stay readable by the old version too, or the rollback restores the old code onto a system it can no longer run.

Let a small slice go first

share of requests sent to the new version time 0% 100% check: compare with the old version check: compare with the old version 5% of requests 25% of requests 100%: promoted check passes: widen check fails: route back to 0% the percentages are an example; each step waits long enough to see real differences
A canary release widens the new version's share of requests in steps, for example 5 percent, then 25 percent, then 100 percent, with a comparison against the old version before each step; a failed comparison sends the new version's share back to zero.

A canary release runs the new version alongside the old one and sends it only a small share of real production traffic at first like tasting a spoonful before serving the whole pot: a small portion goes first, and if it is wrong only that spoonful is wasted. If the new version is bad, only that slice of requests meets it. If it holds up, the share widens in steps, for example from 5 percent to 25 percent to everyone, with a check before each step. The percentages are a choice, not a standard; what matters is that each step exposes the new version to enough real traffic to judge it.

The check is a comparison, not a vibe. Over the same window of time, you put the canary's numbers beside the old version's: error rate, latency percentiles such as p95, resource use, and whatever outcome the change was meant to move. Comparing the two at the same moment is what separates an effect of the release from an ordinary busy hour. The canary is promoted while it stays inside the limits you set in advance, held for more data when the result is unclear, and pulled back to zero when it is clearly worse.

Small apps hit a real limit here. At its peak your app handles about 50 requests per second, so a 5 percent canary sees about 2.5 requests per second, and far fewer at quiet hours. A rare failure, or a modest slowdown against a p95 target of 300 ms, may not show up in a few minutes of that. Google's guidance on canarying sets no universal size; it asks that the canary be large and long-running enough to represent real use, and warns that a handful of requests is not a dependable test. For a low-traffic service the honest options are a bigger slice, a longer wait, or a different strategy.

A canary that saw no errors in a sparse sample has not passed. It has simply not been asked yet.

Deploying is not releasing

deploying puts the code in place; the flag decides who sees it new code running in production deployed once, stays deployed users who see the new feature nobody some users everyone time deploy v2 flag off flag on for some users flag on for everyone kill switch flag off each flag change takes effect with no new deploy
With a feature flag, one deploy puts the new code into production switched off, so no user sees it; later flag changes release it to some users, then everyone, and a kill switch turns it off again, each without a new deploy.

A feature flag, also called a feature toggle, is a condition in your code whose value is read at runtime: if the flag is on, take the new path; if it is off, take the old one. Because the value can change without a new build or deploy, the new code can ship to production switched off, where no user sees it like wiring installed behind the wall with the switch left off: everything is already in place, and turning the light on or off again needs no electrician. Deploying it is one event. Releasing it, turning the flag on, is a separate one, and you can do it whenever you choose.

Once the two are separate, a release can be gradual. The flag can be on for your own account first, then for a small percentage of users, then for more, then for everyone, with the error rate and latency watched at each step and the rollout paused if they get worse. This is a canary done inside the code rather than at the router, and it works even when your app runs as a single copy.

The same mechanism gives you a kill switch. If the new feature misbehaves, turning its flag off takes it away from users without rolling back the deploy, which also leaves alone every other change that shipped with it. Some flags are built to stay for exactly this reason: an operational switch that disables an expensive feature, or falls back to a simpler path, when the system is under strain.

Flags are not free. Each one is a branch in the code with two paths to understand and test, and a release flag left in place after its feature is fully on is dead weight that makes the next change harder. Give every release flag an owner and a removal date, and delete it, along with the old path, once the rollout is done. A flag only switches behavior, too: it cannot take back data the new path already wrote.

Going back, or going through

When a release goes bad there are two ways out. Rolling back means running the previous known-good version again. Rolling forward means shipping a new version that fixes the problem, through the same pipeline as any other change. Both end with working software; they differ in how fast they get there and in what they assume about the state the bad version left behind.

Rollback is cheap only if the previous version is still sitting there, exactly as it was. That is why your deploy should name its container image by a unique version tag or by its digest, never by a moving tag like latest, which can be pointed at a different image between one deploy and the next. With the old image kept in the registry and its version recorded in the deploy history, going back is redeploying a reference you already trust: no rebuild, no guessing which bytes were running yesterday.

Rollback is usually the better first move when the trouble clearly started with the latest change, the previous version is known to work, and it can still use the database as it now stands. It stops the damage quickly; it does not repair it. Roll forward instead when the old version can no longer work with the current schema or data, when a migration has already changed what is stored, or when a small targeted fix is faster and safer than undoing everything that shipped.

What neither path does is rewind the world. Rolling back the code leaves behind every row the bad version wrote, every schema change it applied, and every message, email, or call to another service it already sent. Those need their own repair, from a corrective migration to a restore from backup to a follow-up that undoes an action by doing its opposite. Check this before you reach for the rollback, and rehearse the rollback itself while nothing is on fire, so the first time you run it is not the time you need it.

Schema changes the old version can live with

renaming a column without breaking the previous version release 1: expand release 2: migrate release 3: stop using release 4: contract table columns name full_name (nullable) name full_name (backfilled) name (nullable, unused) full_name name (dropped) full_name each arrow: one more release, shipped and settled what the new app version does writes both columns reads name writes both columns reads full_name writes and reads full_name only no change: only the schema shrinks previous app still works previous app still works previous app still works previous app still works so a rollback of the code never meets a schema it cannot use
Renaming a database column with expand and contract takes four releases: add the new column as nullable, backfill and switch reads to it, make the old column nullable and stop using it, and only then drop it, so at every step the schema still works for the previous version of the app.

Code rolls back; the database does not. Every release strategy that keeps a quick way back, a rolling update, a blue-green switch, a canary pulled to zero, has the previous version of your app running against the current database at some point. So the rule for schema changes is that each one must still work for the version before it. A change that only the new version can live with turns a cheap rollback into an expensive one.

The standard way to keep that rule is expand and contract, also called parallel change. Take renaming a column in your app's users table from name to full_name. Renaming it in place breaks every running copy that still asks for name. Instead, the change ships over several releases like building the new bridge before closing the old one: both stand while traffic moves across, and the old one is demolished only once nothing uses it.

First, expand: add full_name beside name as a nullable column, or one with a default, so inserts from old copies that know nothing about it still succeed, and ship code that writes both. Old copies keep using name and never notice. Next, migrate: copy the existing rows from name into full_name in manageable batches, check the new column is complete, and ship code that reads full_name while still writing both. Then stop using name at all. Before any release stops writing name, drop its NOT NULL constraint or give it a default, or every insert from the new code fails. Only after that has shipped and settled, and nothing running or likely to be rolled back to still touches name, does a later release contract the schema by dropping it.

The slow part is the point. Deleting a column or table destroys data, so a destructive change goes last, in its own release, once no running code and no rollback target depends on what it removes. At every step in between the previous version still works, and rolling back the code never lands it on a schema it cannot use. Your backups remain the last resort for the database, not the plan.

A release you are not afraid of

Taking your app to production means shipping changes to people who did not volunteer to test them. Your app is one container image, one relational database, and a CI/CD pipeline that builds the image once and deploys it, with a few thousand daily users and growing. A release process sized for that does not need every technique here. It needs a few of them done properly.

A sensible starting kit: deploy with a rolling update or a blue-green switch, gated on a health check that proves the app can really serve a request. Tag every image with a unique version and keep the previous ones, so rolling back is one command you have already run in practice. Put risky new features behind a flag with a kill switch, and remove the flag once the feature is fully out. Make every schema change in expand-and-contract steps, so the previous version always works against the current database.

Canary releases earn their machinery as traffic grows. At about 50 requests per second at peak, a small slice of traffic takes a long time to say anything more than "nothing exploded", so a router-level canary buys little today. A flag rolled out to a growing percentage of users gives the same gradual exposure with less plumbing, under the same caveat: give each step enough time and traffic to mean something.

The payoff is that shipping stops being an event. When undoing a change is cheap and practiced, you can ship small changes often, each one easy to reason about and easy to take back, and a bad release becomes a short, contained problem rather than a long night. When one does go wrong anyway, handling it well is its own discipline, which incident response takes up.

Next on your path to Take your own app to production: