Course contentsShow
← Software Engineering
Lesson 1473 of 1,93343. Infrastructure as CodeFree lesson

Immutable vs Mutable Infrastructure

Comparing traditional mutable servers that are patched in-place versus immutable infrastructure patterns and their trade-offs.

Immutable vs Mutable Infrastructure

What you'll learn: You'll understand the fundamental difference between patching servers in-place versus replacing them entirely, and why this choice profoundly impacts reliability and deployment practices.

The Core Distinction

Mutable infrastructure follows the traditional approach: you provision servers once, then continuously update them in-place. Need a security patch? SSH in and apply it. New application version? Deploy over the existing installation. Over time, each server accumulates a unique history of changes—what some call "configuration drift" or "snowflake servers."

Immutable infrastructure takes the opposite approach: servers are never modified after deployment. Instead, you build a completely new server image with all changes baked in, deploy fresh instances, and terminate the old ones. It's replace, not repair.

The Mutable Approach

Think of mutable infrastructure like editing a document in-place. You open it, make changes, save, repeat. This is familiar and seemingly efficient—why rebuild from scratch when you can just patch?

The problems emerge over time: servers diverge from each other, making debugging unpredictable. Rollbacks become complex. You can't be certain what sequence of patches led to the current state.

The Immutable Approach

Immutable infrastructure is like version-controlled documents—you never edit the original. Instead, you create a new version, test it, then swap it in. Every deployment starts from a known, tested baseline.

This approach eliminates configuration drift entirely. Rollback means deploying the previous image. Testing happens on artifacts identical to production. The trade-off? You need robust automation for building and deploying images, and infrastructure changes take longer since you're rebuilding entire systems.

Key Takeaway: Mutable infrastructure patches servers in-place (familiar but prone to drift), while immutable infrastructure replaces servers entirely with each change (more complex automation but eliminates drift and improves reliability).