# Blue-green vs rolling deploys

> Blue-green deploys run old and new versions side by side and switch traffic at once, while rolling deploys replace instances a few at a time.

URL: https://levelrail.com/learn/deploy-operate/blue-green-vs-rolling-deploys/
Updated: 2026-11-27

Both strategies answer one question: how do you ship a new version without users noticing? Blue-green runs two full copies and flips traffic once. Rolling replaces instances one or a few at a time.

## A short history

The blue-green name comes from teams that kept two identical production environments and swapped a router between them. Rolling updates grew out of cluster managers and load-balanced fleets, where replacing every machine at once was never an option.

## How it works

Both strategies rely on something that decides where traffic goes: a [reverse proxy](https://levelrail.com/learn/deploy-operate/what-is-a-reverse-proxy/)) or a load balancer. Deploying means changing what that component points at.

**Blue-green.** Blue is live. You start the new version as green beside it and test it directly, without public traffic. When it passes, you change the proxy to send traffic to green. Blue keeps running for a while. If green misbehaves, you point the proxy back at blue. The [blue-green deploy](https://levelrail.com/learn/glossary/#blue-green-deploy)) switch is a single change, so the rollback is the same change reversed.

**Rolling.** You have several instances behind the balancer, say four. You take one out of rotation, replace it with the new version, wait for its health check to pass, and put it back. Then the next. Between the first and last step, both versions serve users. A [rolling deploy](https://levelrail.com/learn/glossary/#rolling-deploy)) needs little spare capacity, since you only lose one instance's worth at a time.

A worked example on one Docker host with Compose and nginx: run `app-blue` on port 3001 and start `app-green` on 3002. Check green with `curl -fsS http://127.0.0.1:3002/health`. Edit the nginx `proxy_pass` from `127.0.0.1:3001` to `127.0.0.1:3002`, run `sudo nginx -t`, then `sudo systemctl reload nginx`. Reload keeps open connections on the old worker processes until they finish, so most requests are not cut. Stop blue later, after you are sure.

## Comparison

| Question | Blue-green | Rolling |
| --- | --- | --- |
| Rollback speed | One switch, if blue is still running | Roll again, which takes as long as the deploy |
| Spare capacity needed | A full second copy for a while | A little |
| Both versions live at once | Briefly, around the switch | For the whole deploy |
| Works with one instance | Yes, as a swap on one host | No |
| Blast radius of a bug | Everyone after the switch | The share already replaced |
| Typical home | Single host, small teams | Clusters, fleets |

## Common misconceptions

- A switch does not make a deploy free of risk. Everything that depends on shared state still applies.
- Blue-green does not need two servers. Two containers on one host work, if you have the memory.
- Rolling does not mean slow. The speed depends on how long a health check takes, not on the strategy.
- Neither strategy handles database changes for you.

## When not to use it

For a hobby app that can be down for ten seconds, a plain `docker compose up -d` may be the right call. Blue-green on a host with little memory can run out of RAM while two copies run. A rolling deploy of two instances with no spare capacity can drop below what the load needs. Pick the simplest option that meets your uptime need.

## Check it worked

During a deploy, keep requesting your health URL in a loop and watch for failures:

```bash
while true; do curl -fsS -o /dev/null https://example.com/health || echo "fail"; sleep 1; done
```

`-fsS` makes curl fail on 4xx and 5xx but still print errors, and `-o /dev/null` discards the body. A clean deploy prints nothing. Any `fail` line shows a gap to fix. After the switch, `docker compose ps` should show only the version you intend to keep.

## Edge cases and gotchas

- **Database changes break the overlap.** For a time old and new code share one database. Add columns first, ship code that handles both, remove the old column in a later deploy.
- **Sessions can reset.** If sessions live in one instance's memory, a switch logs users out. Use a shared store or signed cookies.
- **Long requests can be cut.** A request in flight on the old version may be dropped when you stop it. Let the old version drain, and give it a stop timeout longer than your slowest request.
- **Background jobs run twice.** Old and new workers can both pick up the same queue or scheduled task. Pause workers on the old version before the switch, or make jobs safe to repeat.
- **A health check that is too shallow.** A check that only returns 200 can send traffic to a version whose database connection is broken. Check what the app needs.
- **Memory on small servers.** Two copies of a heavy app can push a small server into swap or an out-of-memory kill. Check `free -h` first.
- **Cached DNS and sticky connections.** If your switch is a DNS change, clients keep using the old address until the TTL ends. Prefer switching at the proxy.

## Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| 502 right after the switch | Green is not ready or listens on the wrong port | Check green directly first, see [Fix a 502 Bad Gateway](https://levelrail.com/learn/deploy-operate/fix-502-bad-gateway/)) |
| Some users get errors, others do not | Rolling deploy in progress, or one instance is unhealthy | Check each instance's health and logs |
| Users logged out after the switch | Sessions stored in instance memory | Move sessions to a shared store |
| Old code errors on a missing column | Schema change shipped in the same deploy | Use a two-step migration |
| Nginx still sends traffic to blue | Config not reloaded | `sudo nginx -t` then `sudo systemctl reload nginx` |
| Green fails to start with a memory error | Not enough RAM for two copies | Stop other services or add [swap](https://levelrail.com/learn/server-basics/add-swap-space-on-ubuntu/)) |
| Duplicate emails or jobs after deploy | Two workers ran at once | Pause old workers before the switch |
| Rollback to blue shows old data errors | New code changed data in a way old code cannot read | Plan data changes to be reversible |

## Real-world scenario

A solo developer runs an app and Postgres on one VPS. Deploys used to take the site down for about twenty seconds. They switch to a blue-green style swap behind nginx. For one release they need to rename a column. Instead of renaming, they add the new column and keep writing both. They start green on 3002 and check it, then flip nginx:

```bash
curl -fsS http://127.0.0.1:3002/health
sudo nginx -t && sudo systemctl reload nginx
```

The health loop in another terminal prints nothing. Two hours later a bug shows up in a rarely used page. They point nginx back at blue, which is still running, and the page works again. The old column is removed in a later release, once nobody needs the old code.

## Quick reference

| Goal | Command or rule |
| --- | --- |
| Check the new version before switching | `curl -fsS http://127.0.0.1:3002/health` |
| Switch at the proxy | Edit `proxy_pass`, then `sudo nginx -t && sudo systemctl reload nginx` |
| Watch for gaps | Health loop with `curl -fsS` |
| Roll back, blue-green | Point the proxy at the old color |
| Roll back, rolling | Deploy the old version the same way |
| Schema changes | Add first, remove in a later deploy |

## Related lessons

- [Zero-downtime deploys](https://levelrail.com/learn/deploy-operate/zero-downtime-deploys/)): the basics both strategies build on
- [Rollbacks](https://levelrail.com/learn/deploy-operate/rollbacks/)): going back safely after a bad release
- [What is a reverse proxy?](https://levelrail.com/learn/deploy-operate/what-is-a-reverse-proxy/)): the component that switches traffic
- [Restart a Docker app without downtime](https://levelrail.com/blog/restart-docker-app-without-downtime/)): a worked guide for one host

## Next

See what a failed switch looks like and how to fix it: [Fix 502 Bad Gateway behind a reverse proxy](https://levelrail.com/learn/deploy-operate/fix-502-bad-gateway/)).

## Frequently asked questions

### Which deploy strategy is better for a single small server?

Often a blue-green style swap, because a rolling deploy needs several instances to work. Start with whichever you can run and understand.

### Do blue-green and rolling deploys fix database changes?

No. Both run old and new code against one database for a while, so schema changes must work with both versions.

### Why do users get logged out after a blue-green switch?

Sessions stored in the old instance's memory do not move with the traffic. Keep sessions in a shared store, or in signed cookies, so both colors can read them.

### Does a health check make a deploy zero-downtime?

It helps, because traffic only goes to a version that answers. It does not help with in-flight requests or schema changes, which need their own care.
