Welcome to my digital garden. 🌱

Tim Le

What happens when a PR is merged in a typical SaaS

You click the green Merge button and a chain of automated steps starts: CI on main, build, staging, deploy, migrations, feature flags, monitoring and rollback. Here is what a typical SaaS team's pipeline does after the merge, and where it usually goes wrong.

What happens when a PR is merged in a typical SaaS

You review the diff, the checks are green, and you click Merge. For the author, that feels like the end. For the system, it is the start of the most important part: getting the change safely in front of real users.

This post walks through what usually happens after that click in a typical SaaS product. Every company wires it differently, so treat this as a common shape, not a standard. I'll flag the places where I see teams get hurt most often.

The big picture

Six stages after a merge: CI, build, staging, deploy, verify and watch, with a rollback path

Six stages, with a way back from every one of them. Let's go through them.

0. The merge itself

Before any pipeline runs, Git does something small but important. Depending on the repository setting, the PR becomes one of three things on main:

  • Merge commit: keeps every commit from the branch plus a merge commit. Full history, noisy log.
  • Squash and merge: collapses the branch into one commit. Clean log, easy to revert as a unit.
  • Rebase and merge: replays the commits onto main linearly.

Many SaaS teams choose squash, because "revert this PR" then means reverting exactly one commit. That matters later when something breaks at 2 a.m.

The platform also does housekeeping: it closes the PR, may delete the source branch, links the PR to the issue it fixes (and closes it), and notifies reviewers and chat channels.

1. CI runs again, on main

Your branch passed CI before the merge. So why run it again? Because main may have moved. Two PRs can each be green alone and break when combined. This is the classic semantic merge conflict: no text conflict, but behavior conflicts.

A typical post-merge CI job does:

  • install dependencies from the lockfile
  • lint and type-check
  • run unit and integration tests
  • run a security scan on dependencies

Some teams prevent the problem upstream with a merge queue: PRs are tested against the latest main plus the PRs ahead of them before they land. It is slower per PR but keeps main green.

The rule most teams adopt: a red main is the team's top priority. Everyone else's merge is blocked by it.

2. Build an immutable artifact

Once tests pass, the pipeline builds the thing that will actually run. In many SaaS stacks that is a Docker image tagged with the commit SHA. For a frontend it can be a static bundle uploaded to object storage.

docker build -t registry.example.com/app:$GIT_SHA .
docker push registry.example.com/app:$GIT_SHA

The key idea is build once, deploy many. The same artifact goes to staging and then to production. If you rebuild per environment, what you tested is not what you shipped.

Also tagged here: source maps get uploaded to the error tracker, and a release marker is sent to monitoring, so a later graph can show "something changed here".

3. Deploy to staging and test

Staging is a smaller copy of production. The pipeline deploys the new artifact there and runs checks that are too slow or too environment-dependent for CI:

  • Smoke tests: does the app boot, can a user log in, does the main page load?
  • End-to-end tests: a headless browser clicks through sign-up, checkout or the core workflow.
  • Migration dry run: do the database changes apply cleanly to a copy of realistic data?

Staging is never identical to production (less data, fewer integrations, different traffic), so passing there lowers risk but does not remove it.

4. Deploy to production

Now the artifact rolls out. A SaaS cannot go offline for an upgrade, so there are a few standard strategies:

StrategyHow it worksTrade-off
RollingReplace instances a few at a timeSimple, but old and new code run side by side
Blue-greenStart a full new copy, switch traffic at onceInstant rollback, double the capacity briefly
CanarySend 1-5% of traffic to the new version firstCatches problems early, needs good metrics

Notice the first row: old and new versions run at the same time during almost every rollout. That single fact drives the most important rule in the next section.

Database migrations

Schema changes are the riskiest part of a deploy, because you can roll code back but not easily roll data back. The safe pattern is expand and contract:

  1. Expand: add the new column or table. Old code ignores it.
  2. Deploy code that writes to both old and new, and reads the new.
  3. Backfill existing rows.
  4. Contract: in a later release, remove the old column.

Dropping or renaming a column in the same release that stops using it is how teams cause outages: for a few minutes, the old instances still expect it.

5. Verify: is it actually healthy?

A deploy that "finished" is not a deploy that works. Automated checks look at:

  • Health endpoints: does each new instance report ready before it receives traffic?
  • Error rate and latency of the new version compared with the old one
  • Synthetic checks: a script that signs in and performs a key action every minute

With a canary, this step decides whether the rollout continues to 100% or stops by itself. Good setups roll back automatically when error rate crosses a threshold. Weaker ones page a human.

Deploy is not release

One more idea separates mature SaaS teams from the rest: shipping code is not the same as turning on a feature.

Deploy with the flag off, gradual rollout, then release to everyone

The merged code is deployed with a feature flag off. Then product and engineering turn it on for the internal team, then a small percentage, then everyone, watching metrics at each step. If something is wrong, rolling back means flipping the flag, which takes seconds and needs no new deploy.

The cost is discipline: flags that are never removed turn into permanent branching in the code. Give each flag an owner and a cleanup date.

6. Watch what happens next

After the rollout, the PR is still not truly done. In the first hours people look at:

  • error tracking for new exceptions tied to the release marker
  • dashboards for latency, queue depth and database load
  • support channels, because users often notice before dashboards do
  • business metrics, such as sign-up completion, if the change touched that flow

Teams that do this well write the check into the PR: "after release, watch X; if Y moves, revert."

What touches customers outside the code

A merge can set off more than a deploy:

  • Changelog and release notes are generated from PR titles or labels, so write good titles.
  • Docs and API reference may be rebuilt and published.
  • SDKs or packages may be versioned and released, which is why semantic versioning and labels like "breaking" matter.
  • Linked tickets move to "Done" or "In production", which sales and support rely on.
  • Webhooks and chat notifications tell the team what shipped.

Where it goes wrong

These are the failures I see most often, in no particular order:

  • Flaky tests train everyone to click "re-run" until green, so real failures slip through.
  • Migrations that lock a big table during peak traffic.
  • Config or secrets missing in production: it worked in staging because staging had the variable.
  • Cache surprises: a CDN or browser keeps serving old assets, or caches an error response for hours.
  • No rollback plan: the change cannot be reverted because the data format already changed.
  • Merging on Friday evening with nobody watching the dashboards.

A checklist for the person who clicks Merge

Before you click:

  • Do I know how to revert this? Is it one commit?
  • Is the database change backward compatible with the old code?
  • Is risky behavior behind a flag?
  • Do I know which dashboard I will look at?
  • Will someone be around for the next hour?

After you click:

  • Watch CI on main until it is green.
  • Watch the rollout and the error rate for your release.
  • Only then close the ticket and move on.

Conclusion

Merging is a handoff, not a finish line. Behind the button sits CI on main, an immutable build, staging checks, a careful rollout, health verification and monitoring, with rollback available at every stage. The teams that ship fast and sleep well are the ones who invested in that chain: small PRs, backward compatible migrations, feature flags and fast reverts.

If your pipeline is thinner than this, you do not need all of it at once. Start with CI on main, one-command rollback and an error tracker tied to releases. Those three catch most of the pain.