Skip to content

Background

Pets vs cattle

A pet is a machine you name, look after and repair by hand. Cattle are instances built from a definition and replaced when they fail. Cloud works best when most of your instances are cattle.

Two ways to look after a machine

Most long-running estates have pets. The machine called FILESRV02 that holds the file shares was built by hand years ago, has been patched in place ever since, and gets fixed over RDP or SSH when something goes wrong. It works, but nobody could rebuild it exactly, because the steps that made it what it is were never written down.

Cattle are the opposite. Each instance is built from an image plus a definition: a first-boot script, a configuration management playbook, or infrastructure as code. Instances get numbered names such as web-01 and web-02, because any one of them can be replaced by another built the same way. When one fails, you delete it and build a new one.

Pet Cattle
Built by Hand, once A definition, as often as needed
Configuration lives in The machine itself Version control, outside the instance
When it breaks Investigate and repair Replace, then investigate at leisure
To add capacity Build a bigger machine Build more of the same
Knowledge of how it works lives in The people who built it The definition

It works the same on Windows and Linux

Pets vs cattle is sometimes treated as a Linux idea. It isn't. Both operating systems have the same building blocks.

Building block Windows Linux
First-boot setup cloudbase-init runs user data, such as a PowerShell script cloud-init runs user data, such as a shell script or cloud-config
Configuration Ansible over WinRM, or PowerShell Desired State Configuration Ansible over SSH
Starting point A public image, or your own image with a baseline built in A public image, or your own image with a baseline built in
Rebuild The same OpenTofu or Ansible definition, run again The same OpenTofu or Ansible definition, run again

State is what makes a pet

What makes a machine hard to replace is usually not the operating system. It's the state that has built up on its disk: application data, configuration changes made by hand, logs, a certificate someone installed once.

Cattle keep that state somewhere else:

  • Data on a separate volume, in object storage, or in a database that is managed on its own terms.
  • Configuration in a repository, applied at build time.
  • Secrets supplied at build time, not baked into an image.

With state held outside, the instance becomes the easy part to rebuild.

On Breqwatr Cloud

  • Images: every project can launch from Breqwatr's public images, from images you upload, and from snapshots of your own instances.
  • User data: the Breqwatr Cloud Portal (Strata) launch form, the OpenStack CLI and OpenTofu all accept user data, which cloud-init or cloudbase-init runs on first boot.
  • Volumes outlive instances: a data volume can be detached from one instance and attached to its replacement. An instance's root volume is deleted with it by default, which suits cattle: anything worth keeping belongs on a separate volume.
  • Practice: the Rebuild, don't repair tutorial recovers a workload by rebuilding it from code, and Configuration with Ansible shows configuration applied to Windows and Linux instances.

Impact

  • Recovery becomes a rebuild you've already run, rather than an investigation under pressure.
  • Adding capacity means building more of the same, which a definition can do in minutes.
  • Patching can be done by building new instances from a newer image and retiring the old ones.
  • Some software can only run as a single long-lived instance. The pattern gives a direction to move in, not a rule every workload must meet on day one.

Common anti-patterns

  • Fixes that never go back into the definition: a change made by hand on a running instance is lost the next time the instance is rebuilt.
  • Data on the root disk: if the only copy of the data lives on the instance's root volume, deleting the instance deletes the data.
  • Snapshots as the build process: an instance snapshot captures the result, not how it was made. Rebuilding only from snapshots carries every hand-made change forward with it.
  • Cattle with pet names: numbered instances that are still logged into and changed one by one behave like pets, whatever they're called.

Further reading