Skip to main content
mid
intermediate
Infrastructure

Immutable Infrastructure

Question

Explain immutable infrastructure and its benefits. How does it differ from traditional server management?

Answer

Immutable infrastructure means never modifying running instances post-deployment. Instead of patching servers, you build new machine images with updates, deploy fresh instances, and destroy old ones. Benefits include: no configuration drift, consistent environments, easy rollbacks (previous image), simpler debugging (fewer variables), and better security (no SSH access needed).

Why This Matters

The key principle is 'pets vs cattle' - treating infrastructure as disposable rather than precious. Traditional approaches SSH into servers and run updates, leading to drift over time where servers become unique snowflakes. Immutable infrastructure ensures every deployment is identical and reproducible.

Code Examples

Packer AMI build

hcl

Blue-green with new AMI

hcl
Common Mistakes
  • SSH-ing into production servers to make 'quick fixes'
  • Not versioning machine images properly
  • Building images too slowly, making deployments take too long
Follow-up Questions
Interviewers often ask these as follow-up questions
  • How do you handle stateful applications with immutable infrastructure?
  • What tools do you use to build machine images?
  • How do you manage secrets in an immutable infrastructure setup?
Tags
infrastructure
devops
deployment
iac
best-practices