Skip to content
Visual explainer 3h 30m to learn 5 steps

Release and roll back an AI-assisted change

Review configuration, migrations, release checks and monitoring and simulate a failed release and its rollback in a local or preview environment.

By Invicly Tech, , in Prompt Engineering and Vibe Coding. About 10 minutes to read.

Topic 25 of 29

In short

A release is the moment a change leaves your laptop and meets real users. AI-assisted changes can look tidy and still break configuration, data or monitoring, so you check those things on purpose and practise the rollback before you need it.

Think of it like this: Releasing is like a plane taking off: the pilot runs a checklist first, watches the gauges after, and knows where the runway is if the engine fails.

Explained simply

Releasing means putting your change in front of real users. Until then it only runs on your machine, where everything is set up the way you like. A release can fail for boring reasons: a setting is missing, a database does not match the code, or nobody is watching.

AI tools write code quickly, which makes it tempting to release quickly too. The code may look clean, yet the tool cannot see your production settings or your live data. That is your job, and a short checklist does it well.

A good release has a plan for going back. If the new version misbehaves, you want to return to the last good one in minutes. The safest way is to change the database in two steps, so old and new code both work in between.

You do not need a big company setup to practise. A local build, a preview deployment and git revert are enough to rehearse a failed release. Do the rehearsal once, write down what you learned, and the real thing feels calm.

Press Play on a diagram to walk through it one step at a time.

FlowA release with a way back
  1. 1
    Check config

    Every variable the change needs exists in the target environment.

  2. 2
    Expand schema

    Add new columns or tables without removing anything old.

  3. 3
    Deploy

    Ship the code to preview or a small share of traffic.

  4. 4
    Watch

    Errors, latency and logs for the new version.

  5. 5
    Keep or roll back

    Move on if healthy, go back to the last good version if not.

CycleExpand and contract migration
  1. 1
    Expand

    Add the new column. Old code still works.

  2. 2
    Dual write

    New code writes to old and new.

  3. 3
    Backfill

    Copy old data into the new place.

  4. 4
    Switch reads

    Read from the new column.

  5. 5
    Contract

    Drop the old column in a later release.

  6. Back to step 1
SequenceRollback after a failed canary
Engineer
Host
Monitoring
  1. 1Deploy new version to 5% of traffic
    Engineer to Host: Deploy new version to 5% of traffic
  2. 2Error rate rises above the stop rule
    Monitoring to Engineer: Error rate rises above the stop rule
  3. 3Route all traffic to the previous version
    Engineer to Host: Route all traffic to the previous version
  4. 4Error rate returns to normal
    Monitoring to Engineer: Error rate returns to normal
  5. 5Record the cause in the decision log
    Engineer to Engineer: Record the cause in the decision log

In depth

Check environment configuration

Configuration is anything that changes between environments: URLs, keys, feature flags. In Next.js, variables are read from files such as .env.local and from the host. Only variables whose names start with NEXT_PUBLIC_ are sent to the browser, and they are fixed into the bundle when you build. Server-only variables are read at runtime. Keep a list of every variable the change reads and compare it against each target environment. Never commit real secrets. Use placeholders in a file such as .env.example.

  • List variables from the diff, not from memory.
  • Compare preview and production values by name, not by secret value.
  • Rebuild after changing a NEXT_PUBLIC_ value.
  • Fail fast at startup if a required variable is missing.

Plan expand-and-contract migrations

Rolling code back is easy. Rolling data back is not. Expand and contract keeps both versions working. First you expand: add a nullable column or a new table. Then new code writes to both places and you backfill old rows. Then you switch reads. Only in a later release, after you are sure you will not roll back, do you contract and drop the old column. Each step is its own release. An AI assistant often proposes one big migration, so ask it to split the change into these steps.

CompareOne-step change versus expand and contract
One big migration
  • Renames a column in place
  • Old code breaks at once
  • Rollback needs a data restore
  • Short, risky window
Expand and contract
  • Adds new before removing old
  • Old and new code both work
  • Rollback is a code revert
  • Several small releases

Run the checklist and watch

A release checklist is a short list you tick with evidence. Typical items: tests pass, build passes, variables present, migration applied to a copy first, rollback command written, owner named. After deploy, watch for a fixed time. Look at the error rate, response time and logs of the new version. A canary release sends a small share of traffic to the new version first, which limits the damage if something is wrong. Decide the stop rule beforehand, for example roll back if errors double.

  • Name who watches and for how long.
  • Compare against the old version, not against zero.
  • Write the stop rule before you deploy.

Simulate a failure and roll back

Prerequisites: a git repository, Node installed and a local build. Steps: create a branch, add a deliberate bug such as a health route that returns 500, commit it, run the app and confirm the failure with curl. Expected evidence: the status code is 500. Then run git revert on that commit, rebuild and confirm the code is 200 again. Cleanup: delete the branch and stop the server. On a host with preview deployments, the same idea works by redeploying the previous commit. Always revert with a new commit rather than rewriting shared history.

Learn it in 5 short steps

About 40m each. Track them with a timer in your plan.

  1. 1
    Check environment configuration~40m
  2. 2
    Plan expand-and-contract migrations~40m
  3. 3
    Run the release checklist~40m
  4. 4
    Watch for errors after release~40m
  5. 5
    Simulate a failure and roll back~40m

Key points

  • List every environment variable the change reads and confirm it is set in each environment. Variables prefixed NEXT_PUBLIC_ in Next.js are baked into the browser bundle at build time, so they must be right before you build.
  • Never delete or rename a database column in the same release that stops using it. Expand first, contract in a later release, so the old code can still run during a rollback.
  • Write the release checklist before you deploy, and tick items with evidence such as a command output or a link.
  • Decide in advance what 'bad' looks like after release, for example an error rate above the normal level, and who rolls back.
  • Rehearse the rollback in a local or preview environment. A rollback you have never run is a guess.

Key terms

Tap a card to flip it. 0/5 known

Examples

bash
git switch -c release-rehearsal
npm run build && npm test
npm start &
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:3000/api/health
# simulate a failure: break the health route, commit it
git commit -am "Break health route on purpose"
git revert --no-edit HEAD
npm run build && npm start

A local release rehearsal with git. The branch name is a placeholder.

Catch a missing variable before release

A generated change calls a payment provider and reads PAYMENTS_API_URL. The preview has it, production does not. A small startup check turns a vague runtime failure into a clear message during the release checklist.

ts
const required = ["DATABASE_URL", "PAYMENTS_API_URL"];
const missing = required.filter((name) => !process.env[name]);
if (missing.length > 0) {
  throw new Error("Missing environment variables: " + missing.join(", "));
}

Split a rename into safe releases

The assistant proposes renaming users.name to users.full_name in one migration. You ask for expand and contract instead. Release one adds full_name and writes both. Release two backfills and reads full_name. Release three drops name.

sql
-- release 1: expand
ALTER TABLE users ADD COLUMN full_name text;
-- release 2: backfill
UPDATE users SET full_name = name WHERE full_name IS NULL;
-- release 3: contract (later, after a safe period)
ALTER TABLE users DROP COLUMN name;

Quick reference

  • Only NEXT_PUBLIC_ variables reach the browser, and they are fixed at build time.
  • Expand, backfill, switch reads, contract: one release each.
  • Never drop a column in the release that stops using it.
  • Write the stop rule before deploying, not after.
  • Roll back with git revert, which adds a new commit.
  • A canary sends a small share of traffic to the new version first.
  • Keep .env.example with placeholders and never commit real secrets.

Common mistakes

  • Trusting that a green build means the production variables exist. Builds often pass with missing runtime secrets.
  • Dropping a column in the same release as the code change, which makes rollback impossible without restoring data.
  • Skipping the watch step because the deploy 'worked'. Many failures only show under real traffic.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which Next.js variables are available in browser code?

Question 2

2Why is dropping an old column in the same release risky?

Question 3

3What is a canary release?

Question 4

4Which command undoes a shared commit without rewriting history?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    List every environment variable used by a small project and mark which ones are missing in a second environment.

  2. Exercise 2medium

    Turn a one-step column rename into three expand-and-contract releases and write the SQL for each.

  3. Exercise 3hard

    Rehearse a failed release locally and record evidence: status code before, during and after the rollback.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Do I need a staging server to practise releases?
No. A local production build and a preview deployment are enough to rehearse the steps and the rollback.
Is rolling back always the right move?
Not always. If the data has changed in a way old code cannot read, a fix-forward may be safer. Expand and contract keeps rollback possible.
Why not just trust the AI-written migration?
The assistant cannot see your live data or traffic. Review it, run it on a copy and split it into safe steps.

Go deeper

ShareXLinkedInWhatsApp