Immutable infrastructure

On this page 7

Immutable infrastructure is an operating model in which servers, virtual machines and containers are never modified after they are deployed; any change, from a security patch to a new application release, is delivered by building a new image and replacing the running instances. In the Cloud and in Infrastructure as code practice, it turns infrastructure into a sequence of versioned, disposable artifacts rather than long-lived machines that accumulate manual changes.

The approach is the opposite of the traditional mutable model, where administrators log in, upgrade packages and edit configuration files in place. By removing in-place change, immutable infrastructure eliminates most configuration drift, makes every environment reproducible from source, and turns rollback into a simple act of redeploying the previous version.

How immutable infrastructure replaces instead of repairing

Immutable infrastructure works by moving all change into a build pipeline and treating every running instance as read-only at the configuration level. A team defines the operating system, runtime, agents and application in code, a build tool produces a golden image or container image, and an orchestration layer rolls that image out while terminating the old instances.

The lifecycle has a fixed order. Nothing is changed on a live host; instead, the source definition changes, a new artifact with a unique version is produced, it is tested, and it replaces the previous artifact. Data that must survive replacement, such as databases, uploaded files and logs, is kept outside the instance on managed storage or external services.

The following table shows the stages of a typical immutable delivery cycle and what each stage produces.

StageTypical toolingOutput
DefineDockerfile, Packer template, Ansible playbookVersioned image definition in Git
BuildCI runner, Packer, BuildKitMachine image or container image
VerifyUnit tests, image scanning, smoke testsSigned, approved artifact
DeployTerraform, Kubernetes, auto scaling groupsNew instances running the artifact
RetireOrchestrator, lifecycle policiesOld instances terminated and deregistered
Stages of an immutable delivery cycle

Because each artifact is identified by a tag or content digest, the exact software running in production can always be traced back to a commit, a build log and a test report. This traceability is one of the main reasons regulated industries adopt the model.

Mutable and immutable models compared

The essential difference between the two models is where change happens: on the running server in the mutable model, or in the build pipeline in the immutable model. Configuration management tools such as Chef and Puppet were designed largely for the mutable world, where an agent repeatedly converges a long-lived host toward a desired state.

The comparison below summarizes how the two models behave across the properties that matter most in operations.

PropertyMutable infrastructureImmutable infrastructure
Change methodIn-place updates on live hostsRebuild and replace instances
Configuration driftCommon and gradualLargely eliminated
RollbackReverse each change manuallyRedeploy the previous image
Server lifespanMonths or yearsHours to weeks
Debugging accessRoutine SSH accessRestricted or disabled shell access
Build costLow per changeHigher, since every change needs a build
Audit trailScattered across hostsCentralized in pipeline and registry
Mutable versus immutable infrastructure

In practice, many organizations run a hybrid model: immutable images for stateless compute and mutable, carefully managed systems for stateful components such as primary databases. The term describes a discipline applied to specific layers, not necessarily to an entire estate.

Immutable infrastructure depends on several cooperating components: an image builder, an artifact registry, a provisioning tool and a deployment strategy that can swap instances without downtime. Infrastructure as code tools such as Terraform, OpenTofu, Pulumi, AWS CloudFormation and Bicep describe the surrounding resources declaratively, while the images themselves hold the server contents.

The next table maps the main building blocks to their role and to common examples.

ComponentRoleCommon examples
Image builderProduces the immutable artifactPacker, Docker, Buildah
Artifact registryStores versioned imagesContainer registries, machine image catalogs
Provisioning toolDeclares networks, groups and policiesTerraform, Pulumi, CloudFormation
OrchestratorSchedules and replaces instancesKubernetes, auto scaling groups, managed instance groups
External state storeKeeps data outside instancesManaged databases, object storage, log services
Core components of an immutable setup

Configuration tools such as Ansible still have a place, but their role shifts: they run once at build time inside the image pipeline rather than repeatedly against production hosts. Policy as code checks can also gate the pipeline, rejecting images that contain known vulnerabilities or unapproved packages.

Deployment strategies that make replacement safe

Replacing instances is only safe when the deployment strategy controls how much traffic reaches the new version and how quickly the old version can return. The choice of strategy determines downtime, cost and the size of the blast radius when a release is faulty.

The decision table below connects common situations with a suitable rollout strategy.

SituationRecommended strategyReason
Large stateless web fleetRolling replacementGradual swap with modest extra capacity
Release needing instant rollbackBlue-green deploymentTraffic switch back to the intact old fleet
High-risk change with real usersCanary releaseSmall traffic share exposes defects early
Batch or worker nodesDrain and replaceJobs finish before termination
Strict cost limitsRolling with small batchesAvoids doubling capacity during release
Choosing a rollout strategy for immutable releases

Health checks are central to every strategy. A new instance must pass readiness and liveness checks before it receives traffic, and the orchestrator must halt the rollout automatically when error rates rise.

Limitations, costs and common mistakes

Immutable infrastructure is not free: it demands mature automation, fast builds and disciplined handling of state. Teams that adopt the label without these foundations often end up with a slower and more fragile process than the one they replaced.

The following table lists frequent problems, their usual cause and the corrective practice.

ProblemTypical causeFix
Emergency SSH hotfixesNo fast path for urgent patchesShorten build time and automate patch images
Lost data after replacementState kept on local disksMove state to managed external storage
Slow releasesMonolithic images rebuilt from scratchUse layered base images and build caching
Image sprawlNo retention policy in the registryExpire unused versions automatically
Secrets baked into imagesCredentials copied at build timeInject secrets at runtime from a vault
Common problems and fixes
  • Debugging changes: engineers rely on centralized logs, metrics and traces instead of inspecting a live host.
  • Base image hygiene matters: an outdated base image spreads the same vulnerability to every instance built from it.
  • Stateful systems resist the model and usually need managed services or specialized operators.
  • A manual change on a running host, even once, silently breaks the immutability guarantee for that host.

Stripped to the essentials

Immutable infrastructure means that a server is never repaired or adjusted while it runs. When something needs to change, the team prepares a fresh, complete copy with the change already included, starts it, and switches the old one off.

Think of printed books rather than a whiteboard. Nobody corrects a printed page with a pen; a new edition is printed instead, and every reader of that edition sees exactly the same text. The result is predictable systems, easy rollback to the previous edition, and far fewer surprises caused by forgotten manual changes.

Where it is applied

An online retailer runs its storefront on about 60 virtual machines behind a load balancer. Previously, administrators patched each machine by hand every month, and after two years no two servers were configured identically, which caused intermittent checkout failures that nobody could reproduce.

The platform team moves to an immutable pipeline. Each merge to the main branch triggers Packer to build a new machine image, which is scanned, tested and tagged with the commit hash. Terraform updates the launch template, and the auto scaling group performs a rolling replacement in batches of 10 percent, stopping automatically if error rates rise.

Within one quarter, monthly patching shrinks from two days of manual work to an automated 40-minute rollout, the intermittent checkout failures disappear because every server is identical, and a faulty release is reverted by redeploying the previous image in minutes.