Pet vs cattle in a cloud-native world
Disclaimer: No animals were harmed in writing this article and I am a vegetarian ;-)
While talking about the containers (Docker and Kubernetes) to the beginners, we start by telling that a container is more like a light-weight virtual machine(VM).
A container provides isolation from the host OS as VMs do.
It has its own IP address, process space and storage area.
But this definition of a container has its own limitation, especially when we discuss various container orchestration concepts and the usefulness of the features provided by container orchestration tools like Swarm and Kubernetes.
That is when it is important to bring forth the difference between VMs and Containers by giving an analogy of pet vs cattle.
Virtual machines are more like pets. Containers and pods are more like cattle.
What is the difference between pets and cattle?
We love our pets.
Normally there are only a limited number of pets a person have.
These are high maintenance.
If something happens to them, we go to hospitals.
We provide care for them to recover.
It is a long term relationship with pets.
On the other hand, there are cattle. Chicken, sheep etc.
Cattle are ephemeral.
These are here for a very specific purpose.
They require low maintenance cost.
If there is a flue, normally these are culled without much remorse.
Ops engineers by default treat the infrastructure as 'pets', but microservices-based and the cloud-native world is revolving around the 'cattle' concepts.
The aspect of agility, scalability and high availability of our application is being achieved by moving towards a "cattle" mindset from a "pet" mindset.
Once you keep this fundamental difference between VMs (Pet) and containers (Cattle) in mind, you will appreciate the importance of those complex concepts of kubernetes. It will make you wiser while making judgment calls about the application architecture.
It helps you give a better clarity for the question such as -
- Co-existence of VMs and Containers.
- When to use VMs and when to use containers?
- What should be a good design pattern for your application?
- How to work with the data and databases?
- How to ensure scalability and flexibility?
- Falling fast and healing faster.
A seasoned software professional would be enticed to make decisions with the pet mindset, as it seems to be the right thing to do, no matter how painful it is. But if you are planning to move to a cloud-native ecosystem, it is imperative that you know what works as a pet what works as cattle, when to cure and when to cull.
P.S.: If you are wondering about the application of this concept in real life here is a link to my other article where a worker-node was culled like a cattle.