{"canonical_url":"https://engineer.company/glossary/blue-green-deployment/","content_markdown":"# Blue-green deployment\n\n## What it is\n\nBlue-green deployment is a way of releasing software with two production\nenvironments built to be as alike as possible. One of them, called blue here,\nserves every request. The new version is installed on the other, green, and\ntested there while no customer traffic reaches it. When it is ready, whatever\nsits in front of the two is changed so that every new request goes to green.\nBlue keeps running untouched, and if green misbehaves, the same change made in\nreverse puts blue back in service.\n\nThe colours carry no meaning, which is the point of them. Names such as \"old\"\nand \"new\" or \"primary\" and \"standby\" swap meaning after every release, while two\ncolours simply take turns: after the next switch green is live and blue is the\nidle one. Martin Fowler described the technique on his bliki in 2010 and\nattributes the name, a little hazily, to Daniel Terhorst-North and Jez Humble.\nThe usual spelling has a hyphen, though tools write it their own way: Argo\nRollouts, a Kubernetes controller that adds deployment strategies of this\nkind, calls it `blueGreen` in its configuration.\n\nThe switch can be any single point that decides where requests go. Fowler's\nversion changes a router. It can equally be a load balancer's target, a reverse\nproxy's upstream, or in Kubernetes a Service whose label selector picks the Pods\nthat receive its traffic. The two environments do not have to be two data\ncentres either: Fowler lists separate hardware, separate virtual machines, or\ntwo zones on one system with their own IP addresses as all good enough.\n\nTwo neighbouring techniques make the contrast clear. A rolling update replaces\ninstances a few at a time, so old and new versions answer requests side by side\nuntil the last old one is gone, and rolling back means rolling forward again in\nthe other direction. A canary release sends a small share of traffic to the new\nversion first and widens it step by step. Blue-green moves everything at once,\nbut keeps a complete, running copy of the previous version, so the way back is\none step, the same size as the way forward.\n\n## Why it matters\n\nA release becomes a short, reversible event instead of a long, one-way one. The\nslow parts, copying files, starting processes, warming caches, happen on green\nwhile blue is still serving, so customers never wait on them. The switch itself\nis quick, and so is undoing it: nothing is rebuilt or reinstalled, because the\nprevious version never stopped. That changes how a team feels about releasing on\nan ordinary afternoon, and how quickly it can act when something looks wrong.\n\nGreen can also be checked in conditions very close to production before any\ncustomer sees it: the same network, the same configuration, the same database.\nA smoke test against green proves far more than the same test in a staging\nenvironment that differs in a dozen small ways. Argo Rollouts formalises this\nwith a preview Service, which routes to the new version before promotion so it\ncan be tested without serving production traffic.\n\nThe idle environment has a second job. Once a release has settled, the side that\njust went quiet becomes the place to stage the next one, and in the meantime it\nis a warm standby. Fowler points out that the same mechanism \"allows you to test\nyour disaster-recovery procedure on every release\", because every switch is a\nfailover that someone is watching.\n\nThe costs are plain. Two production environments need two environments' worth\nof capacity, at least for the duration of a release. And while the application\ntier is easy to duplicate, the data is not: blue and green nearly always share\none database, which means every release has to be readable by both versions. A\nteam that cannot guarantee that gets a fast switch forward and a broken switch\nback.\n\n## What it looks like in practice\n\nOn Kubernetes, the smallest working version is two Deployments and one Service.\nThe Deployments `web-blue` and `web-green` run the same application with the\nlabels `app: web` and `slot: blue` or `slot: green`. The Service that customers\nreach selects one slot:\n\n```yaml\napiVersion: v1\nkind: Service\nmetadata:\n  name: web\nspec:\n  selector:\n    app: web\n    slot: blue\n  ports:\n    - port: 80\n      targetPort: 8080\n```\n\nA release puts the new image on the idle side, waits for it, tests it through a\nsecond Service that selects `slot: green` alone, and then moves the live one:\n\n```sh\nkubectl set image deployment/web-green web=registry.example.com/web:1.5.0\nkubectl rollout status deployment/web-green --timeout=5m\n# smoke tests against the web-green preview Service go here\nkubectl patch service web -p '{\"spec\":{\"selector\":{\"slot\":\"green\"}}}'\n# the way back is the same command with the other colour\nkubectl patch service web -p '{\"spec\":{\"selector\":{\"slot\":\"blue\"}}}'\n```\n\n`kubectl patch` defaults to a strategic merge patch, so only the `slot` key of\nthe selector changes and `app: web` stays where it was. The Service controller\nkeeps scanning for Pods that match the selector and updates the Service's\nendpoints when the set changes, so new connections land on green while blue\nsits ready with the previous image.\n\nArgo Rollouts automates the same dance with one `Rollout` object: an\n`activeService` that it points at the new pods on promotion, and an optional\n`previewService` that reaches them before. With `autoPromotionEnabled: false`\nthe rollout pauses before the switch until someone runs\n`kubectl argo rollouts promote web`.\n\nThe [DevOps and CI/CD service](/services/devops-cicd/) promises changes that are\ntested, released and reversible, and blue-green deployment is one way to make\nthe last of those cheap. It rests on two habits that\n[deployments of one platform to Azure](/portfolio/owned-end-to-end-platform-deployments-to-azure/)\nshow at work, without any second production slot: Bicep templates keep the\ntarget infrastructure identical from one environment to the next, and the same\nbuilt artefact is promoted from development through staging to production,\npicking up each environment's settings where it lands. That route moves a\nrelease through environments in a line. Blue-green adds a twin at the end of\nit, and the same two habits, identical infrastructure and one unchanged\nartefact, are what let a team trust that the twin really is one.\n\n## Where it goes wrong\n\n**A schema change turns the way back into a dead end.** Green starts, runs a\nmigration that renames a column, and serves traffic happily. Ten minutes later a\nfault sends traffic back to blue, which still asks for the old column name and\nfails on every request. The rollback was planned for the application and not for\nthe data. Fowler's advice from 2015 is to separate the two: ship a database\nchange that both versions can work with, then the application, and remove what\nonly the old version needed once the new one has settled.\n\n**State written on green is stranded by a switch back.** Anything green keeps\nfor itself, such as files uploaded to its local disk, an in-memory session store\nor its own cache of pending jobs, is not on blue when traffic returns there.\nUsers find themselves logged out or missing what they just saved. Keep shared\nstate in stores both colours use. Where green must have its own data, Fowler\nsuggests feeding transactions to both environments, or starting green read-only\nand switching it to read-write only once it has proved itself.\n\n**The way back is scaled away before the fault shows.** Argo Rollouts scales the\nold ReplicaSet down after the switch, and `scaleDownDelaySeconds` defaults to\n30. A fault that appears after a quarter of an hour, a nightly job or a slow\nleak, finds no blue to return to. Set the delay to cover the time it usually\ntakes for trouble to surface, and accept that the price is the capacity:\n\n```yaml\nstrategy:\n  blueGreen:\n    activeService: web\n    previewService: web-preview\n    autoPromotionEnabled: false\n    scaleDownDelaySeconds: 3600\n```\n\n**Promotion follows readiness, not correctness.** `autoPromotionEnabled`\ndefaults to true, which means Argo Rollouts switches as soon as the new pods are\nready. A readiness probe tells you a process answers, not that checkout works.\nPause before promotion as in the block above and test through the preview\nService, or attach a `prePromotionAnalysis`, which aborts the rollout when it\nfails, and a `postPromotionAnalysis`, which switches back to the previous\nversion when it fails after the switch.\n\n**The idle side drifts.** Between releases, someone applies an urgent\nconfiguration change to the live environment only. The next release lands on the\nidle side, which still has the old setting, and the switch that was supposed to\nchange one thing changes two. Build both slots from the same templates and the\nsame configuration source, so a change to one is a change to both, and treat the\nidle side as the next release's staging area, as Fowler describes.\n\n## Further reading\n\n- [Blue Green Deployment](https://martinfowler.com/bliki/BlueGreenDeployment.html)\n  — Martin Fowler's 2010 description, with his 2015 note on database changes.\n- [Argo Rollouts: BlueGreen](https://argo-rollouts.readthedocs.io/en/stable/features/bluegreen/)\n  — active and preview Services, automatic promotion, analysis before and after\n  the switch, and the scale-down delay.\n- [Kubernetes Service](https://kubernetes.io/docs/concepts/services-networking/service/)\n  — how a selector picks the Pods that receive a Service's traffic.\n- [kubectl patch](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_patch/)\n  — strategic merge, merge and JSON patches, the command that flips the selector\n  in the example above.\n\n\u003chttps://engineer.company/glossary/blue-green-deployment/\u003e\n","date_modified":"2026-10-29T11:17:41Z","description":"Two identical production slots, one switch between them: how a release goes live at once, how it goes back, and what the database demands first.","formats":{"gemtext":"https://engineer.company/glossary/blue-green-deployment/index.gmi","gopher":"https://engineer.company/glossary/blue-green-deployment/gophermap","html":"https://engineer.company/glossary/blue-green-deployment/","json":"https://engineer.company/glossary/blue-green-deployment/index.json","markdown":"https://engineer.company/glossary/blue-green-deployment/index.md","pdf":"https://engineer.company/glossary/blue-green-deployment/index.pdf"},"kind":"page","language":"en","title":"What is blue-green deployment?","url":"https://engineer.company/glossary/blue-green-deployment/","version":1}