What is immutable infrastructure?
BeginnerConceptInfrastructure & cloud basics
Answer
In one line: Immutable infrastructure means you never modify servers or containers after they're deployed — to change anything, you build a new image and replace the old instances.
Mutable vs immutable:
- Mutable (traditional): SSH into servers and run updates, patches and config changes in place. Over time each server becomes slightly different.
- Immutable: bake a new image (AMI or Docker image) with the change, deploy new instances from it, and destroy the old ones.
How it works in practice:
- Containers: to update the app, build
orders:1.4.3and roll it out; you neverdocker execin and edit files. - VMs: build a "golden image" with Packer (OS + patches + agents + app), then replace instances in an Auto Scaling Group using a rolling instance refresh.
Benefits:
- No configuration drift — every instance from the same image is identical.
- Predictable deployments — the image you tested is exactly what runs.
- Easy rollback — redeploy the previous image.
- Better security — no SSH changes needed; servers can be locked down; patches come via new images.
- Fits autoscaling — new instances are ready instantly from the image.
Challenges:
- Needs good automation (image pipelines, rolling replacement).
- State must live outside the instances — databases, object storage (S3), persistent volumes — because instances are disposable.
- Image builds take time, so small fixes still mean a full image cycle.
Pets vs cattle: mutable servers are "pets" (named, cared for individually); immutable ones are "cattle" (identical and replaceable).
Example: a monthly OS patch used to mean SSH-ing into 40 servers. Now a Packer pipeline builds a patched AMI, and an Auto Scaling Group instance refresh replaces servers one batch at a time with zero downtime.
Tip for interviews: mention Packer + Auto Scaling or containers, and that state must live outside the instances.
More on Infrastructure & cloud basics
What is the difference between declarative and imperative infrastructure?BeginnerWhat is idempotency, and why is it important in automation?BeginnerWhat is configuration drift, and how do you prevent it?BeginnerWhat does "pets vs cattle" mean?BeginnerWhat is cloud computing, and what are IaaS, PaaS and SaaS?BeginnerWhat is the shared responsibility model in the cloud?Beginner