AI Agent Blue Green Deploy 2026
Blue-green means two identical environments: blue serves traffic, green holds the new build. After verification you point the entry at green; if anything breaks you point it back, in seconds, without rebuilding. For agents, where one prompt edit can change every answer, instant rollback matters more than deploy speed.
📜 Table of Contents
📖 Keep reading
Blue-Green Deployment for AI Agents
Two identical environments, one serving traffic. Cut over when verified, cut back in seconds when not. For a system where a single prompt edit changes every answer, that instant rollback is worth more than deploy speed.
Is your agent a good fit?
| Scenario | Fit | Why |
|---|---|---|
| Stateless HTTP API | Good | Switch entry point, rollback is trivial |
| Sessions in process memory | Needs work | Users lose state on cutover |
| Long-lived SSE / WebSocket | Needs draining | Old connections do not migrate |
| Scheduled workers | Needs a leader lock | Both sides will run the cron |
| Concurrent schema change | Needs expand-contract | Both versions read one table |
Topology
┌──────────────┐
users ───────▶│ nginx │
└──────┬───────┘
┌──────┴───────┐
blue │ │ green
127.0.0.1:8001 127.0.0.1:8002
└──────┬───────┘
Redis / PostgreSQL
Both slots share external storage. Anything kept in process memory is lost at cutover.
Switching with nginx
Keep each upstream in its own file and point a symlink at the active one:
# /etc/nginx/upstreams/green.conf
upstream agent_backend {
server 127.0.0.1:8002 max_fails=3 fail_timeout=10s;
}
ln -sfn /etc/nginx/upstreams/green.conf /etc/nginx/conf.d/agent-upstream.conf
nginx -t && nginx -s reload
nginx -t validates first, so a bad config never reaches a reload. Rollback is the same two commands with blue.conf.
In the server block, raise proxy_read_timeout for streaming responses and set proxy_buffering off, otherwise SSE output is buffered and arrives in one burst.
Running both slots
services:
agent:
image: registry.example.com/agent:${TAG}
ports:
- "${PORT}:8000"
env_file: .env
stop_grace_period: 60s
TAG=v1.4.2 PORT=8001 docker compose -p agent-blue up -d
TAG=v1.5.0 PORT=8002 docker compose -p agent-green up -d
Four checks before cutover
/healthzmust probe Redis, the database and the model endpoint — a bareokproves nothing- Replay 10-20 real requests against both slots and diff format, key fields and refusals
- Warm the new process: the first model call pays for connection setup and TLS
- Watch logs for five minutes, especially tool timeouts and token anomalies — neither shows up as an HTTP error
Schema changes: expand-contract
| Phase | Action | Old code still works? |
|---|---|---|
| Expand | Add fields/tables, old code ignores them | Yes |
| Migrate | Backfill history in the background | Yes |
| Switch | New code reads/writes new fields | Yes |
| Contract | Drop old fields once rollback is off the table | Not needed |
Do it in the wrong order and a rollback lands on code that cannot read the data.
Prompts and models are versions too
PROMPT_VERSION, MODEL_NAME and temperature belong to the release. Stamp them into the container environment and log them at startup so a rollback moves all of it together, not just the image tag.
Four traps
- Sticky sessions: keep session state in Redis with a TTL, never in process memory
- Connection draining: on SIGTERM stop accepting, finish in-flight requests, then exit; a hard kill truncates live SSE streams
- Duplicate cron: two slots both running the job doubles the bill; elect a leader with a Redis lock
- Cache keys: include the prompt version, or the new build serves answers generated by the old prompt
FAQ
Blue-green or canary? Blue-green switches everything at once and rolls back fastest. Canary ramps traffic and suits high-volume services. A common pairing: blue-green for code, canary for prompt changes at 5%, 20%, 100%.
Only one machine? Run the new build on a second port, keep the old process alive until verification finishes, then switch the upstream.
Do in-flight requests break? nginx -s reload is graceful; the risk is the backend exiting immediately. Handle SIGTERM and drain.
How long to verify? Ten minutes plus real samples. Flows with side effects deserve a full business cycle, not a 200 status.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.