კითხვაBlue-green or canary on one VPS, and rollback after a DB migration

TP Tomasz P. წევრი რეგისტრაცია: 30 ივნ. 2026
პოსტები: 84
#1

Small app: one VPS, nginx in front, Node behind. Now deploy = stop, update, start, and the site is down for some seconds.

Questions:
1. Is blue-green possible on one server?
2. Canary needs Kubernetes, or not?
3. How to roll back if the new version already ran a DB migration?

YS Yury Slinkin თანამშრომელი · ადმინი რეგისტრაცია: 6 ივნ. 2026
პოსტები: 94
#2

1. Yes. Run two instances on different ports (say 3001 and 3002), nginx proxies to whichever is live. In nginx:

upstream app {
    include /etc/nginx/conf.d/app-upstream.inc;
}

Deploy: start the new version on the idle port, wait for its health check, switch the include, reload nginx:

#!/usr/bin/env bash
set -euo pipefail
NEW_PORT="$1"

for i in $(seq 1 30); do
  if curl -fsS "http://127.0.0.1:${NEW_PORT}/healthz" > /dev/null; then
    break
  fi
  if [ "$i" -eq 30 ]; then
    echo "new instance is not healthy, staying on the old one" >&2
    exit 1
  fi
  sleep 1
done

echo "server 127.0.0.1:${NEW_PORT};" > /etc/nginx/conf.d/app-upstream.inc
nginx -t
nginx -s reload

Rollback is the same script with the old port, as long as you keep the old instance running for a while. nginx -s reload lets current connections finish on the old workers.

2. No Kubernetes needed. Two servers in the upstream with weights is already a canary:

upstream app {
    server 127.0.0.1:3001 weight=9;
    server 127.0.0.1:3002 weight=1;
}

For sticky users (same person always gets the same version) look at split_clients in the nginx docs.

ER Evgeny Rudenko წევრი რეგისტრაცია: 14 აგვ. 2026
პოსტები: 86
#3

3 is the hard part. The rule that makes rollbacks possible: the new code must work with the old schema, and the old code must work with the new schema. That is the expand/contract pattern:
1. Expand: add the new column as nullable, no code reads it yet.
2. Deploy code that writes both old and new.
3. Backfill old rows.
4. Deploy code that reads the new column.
5. Contract: drop the old column in a later release.

At every step, rolling back means "old code, same database". In production I wouldn't rely on down migrations: they are rarely tested and they can lose the data written since the deploy.

If a migration is destructive (drop, type change with data loss), deploy cannot undo it, only a restore from backup can. That is exactly why the drop goes last, after the version that no longer reads the column has run for a while, and with a fresh backup taken right before it.

TP Tomasz P. წევრი რეგისტრაცია: 30 ივნ. 2026
პოსტები: 84
#4

Clear, thank you. So:
1. Rollback = old code, database stays.
2. Drop column = separate release at the end, backup before.

SL Sara L. წევრი რეგისტრაცია: 17 ივლ. 2026
პოსტები: 80
#5

If you run it with docker compose instead of two node processes, docker compose up -d --wait blocks until the containers are running and healthy, and exits non-zero if not. Pairs well with the HEALTHCHECK from https://batume.li/en/forum/352.

სწრაფი პასუხი

წერა შეუძლიათ მხოლოდ შესულ წევრებს. შესვლა