Why you need it
The servers are built from the code, and then someone fixes one by hand at 2am. Now that server no longer matches the code, and nobody wrote down why. Two servers that should be identical behave differently, and the next rebuild quietly throws the fix away.
Think of it like this
Printing a document again instead of fixing a copy with a pen. A pen fix lives on one sheet and is gone the next time you print. Fix the file, and every new print has it.
Where you’ll find it
- AWS: Instance refresh swaps every server in a group for a fresh one built from a new image.
- Kubernetes: A Deployment never edits a running copy: a change means new copies replace the old ones.
- HashiCorp: Packer bakes a finished server image from code, so every new server starts from the same picture.
- Drift checks: Terraform and CloudFormation can compare the real servers with the code and list what no longer matches.
What to know first
Built from code. The servers come from settings written in a file, not from clicks. See Infrastructure as code.
Drift. When a real server slowly stops matching its code, one hand change at a time.
Image. A saved, finished copy of a server's disk that new servers start from.
How it works
- A hand fix makes drift. Ben changes server 1's disk from 50 GB to 100 GB by hand. The code still says 50. The strip turns red in the animation: this is drift.
- Rebuilding loses the fix. Server 1 dies and is built again from the code. The code says 50 GB, so the new server has 50 GB, and the problem Ben fixed comes back.
- Change the code instead. Ben changes the row in the code to 100 GB. Now the fix is written down, reviewed, and part of every future server.
- Replace, never patch. The old servers are thrown away and new ones are built from the new code. Nobody logs in to change a running server. This is "immutable": once built, a server is never changed, only replaced.
- Catch drift early. Tools can compare the real servers with the code on a timer and flag anything that no longer matches, before it surprises you.
An example
Ten servers are built from code that says disk: 50 GB. Over a year, people make 3 hand fixes on 3 different servers.
Now there are 4 kinds of server, and a bug that shows up on only 1 in 10 visits, because only some servers have the problem.
Immutable way: each fix goes into the code, and all 10 are replaced from it. Ten servers, one kind, and the bug is either everywhere or nowhere.
Further reading
- ImmutableServer, Kief Morris, on martinfowler.com. The short page that named the idea. Start with this one.
- PhoenixServer, Martin Fowler, on martinfowler.com. Why you should burn servers down and rebuild them on purpose, often.
- Manage resource drift, Terraform tutorials. A hands-on look at finding drift and bringing servers back in line.