The Principle of Immutability

As covered in previous blogs, my favorite software design and architecture principles are:

  1. The Git Principle
  2. The Maven Principle
  3. The Principle of Immutability

In this blog, I am going to cover the principle of immutability. This is the only principle that is not a side-effect of technology or framework among my core principles.

The immutability principle is so universal that it can be appreciated at the most basic level and at the most advanced level. We can also look at it from an Object-Oriented programming perspective. Every object has a state and behavior. The internal state is its own business, and the only way an object should be modified is via behavior. The internal state of an object being hidden is called encapsulation.

Immutability takes this one step ahead with not even allowing the internal state of an object to be changed. In other words, if the internal state is changed, it’s no longer the same object. This new mutated object needs to be identified with a new identifier. If we use the language of security, it’s equivalent to an object having a different checksum. If we use the language of gitOps, it’s equivalent to an object having a new version.

In n-tier object-oriented design, the principle of immutability is most visible in the creation of data transfer objects or value objects.

The principle of immutability intersects multiple Gang of 4 design patterns. The immutable artifact creation can be related to the factory method. Artifact cloning can be related to the prototype and memento pattern. Updating artifacts can be related to the state pattern.

When designing the Roost.ai Environments as a Service platform, one of the key considerations was how best we could provide immutable infrastructure for pre-production workloads. Following the pattern in the previous section, roost platform:

  1. Instantly creates versioned environments (using blueprint created from repository inference).
  2. Creates as many copies of the environment as needed.
  3. Update environments as the source repository changes.

This post was created with Typeshare

--

--

This blog is mostly around my cloud-native & Environments-as-a-Service (EaaS) technology insights. I would throw some crypto wisdom here and there.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rishi Yadav

This blog is mostly around my cloud-native & Environments-as-a-Service (EaaS) technology insights. I would throw some crypto wisdom here and there.