In this article, we’ll learn about the principles of isolation. When building microservices, one of the primary goals is to achieve a higher degree of isolation between components within our application. As a result of isolation, Microservices built have loose coupling and increased scalability.
Reactive Microservices have isolation in State, Space, Time, and Failure. All these principles of isolation have their own importance and advantages. We’ll see in brief detail about what each of these principles of isolation in this section.
Also Read: When Reactive Meets Microservices
Principles of Isolation in Reactive Microservices
Let’s have a look at the principles of isolation in Reactive Microservices. They specify the basis on which we can isolate our microservices. By following these principles, microservices are independently deployed and executed within a separate process.
1. Isolation of State
Firstly, we have the isolation of the state. This principle allows the reactive microservice to evolve internally without affecting the outside because it only communicates through the public-facing API. We do not have any backdoor access through the database and hence the API is the only mode of communication.
As long as we maintain that public-facing API, nobody needs to know what happens under the covers. Nobody needs to know that we have changed databases, restructured the database, nobody needs to know that we rewrote the domain code. Therefore, All of that can evolve independently. That’s the main idea behind the isolation of State.
2. Isolation in Space
Next, we have Isolation in space. Reactive microservices are independently deployed. They do not care about the location of other microservices. That is to say, it does not care whether it is deployed to the same piece of hardware or maybe a different piece of hardware.
Likewise, It does not care whether it is deployed in the same datacenter or maybe a totally different datacenter. It has a single method of communication that works no matter where the other microservices are deployed.
As a result of this, we can scale up or down the microservices to meet the requirements. We can spin up any number of copies of the Customer service if necessary across many different pieces of hardware without any issues.
If possible we may even have them deployed on different datacenters. Therefore, even if we lose an entire datacenter the application continues to operate normally.
3. Isolation in Time
Next, we have isolation in time. In reactive microservices, requests are asynchronous and non-blocking. This allows us to use our resources in a more efficient manner. Rather than having a situation where we send a request, and then we block a thread while we wait for a response. What we’re doing is we send a request and then we walk away.
That allows for more efficient use of resources because we don’t have to occupy that thread and threads aren’t free. Also, it’s not just the threads, we can free up things like memory, we can free up CPU, all of these things.
Between microservices, we expect eventual consistency. Within a microservice, we can perhaps have strong consistency but between microservices, we expect eventual consistency. This provides increased scalability.
4. Isolation of Failure
At last, we have isolation of failure. The main idea of this principle is to isolate the failure, which in turn prevents the cascading failures. Therefore, It allows the system to remain operational in spite of failure.
The more we follow this principle, the more robust our system is going to be. In an ideal case, if we can get to the point where any one of our services can operate completely independently of all the others, then that leaves us in a really good state.
What is the Need for Isolating Microservices?
- By increasing isolation within the application, we can achieve flexibility and power.
- Isolation restricts access to the data of the service strictly to that service’s API.
- Limiting access to the API of service allows the underlying persistence model to have complete abstraction from the application’s other services.
- Isolating applications in space help us to manage resource utilization by allowing us to redistribute an application’s components dynamically.
- Isolating the application in time using asynchronous service calls eradicate the need for resources to wait for long-running requests.
- The distribution of load across the isolated application is way better than the load distribution followed by service-oriented architecture.
- Isolating the application components from failure prevents cascading failures.
- Isolation avoids the crashing of the entire application as there is no single failing component.
One of the biggest issues we can face when dealing with microservices is to ensure each microservice operates in complete isolation from its microservice siblings. There are plenty of great tools and cloud services out there nowadays which can help us to follow these principles of isolation. However, it is up to you to ensure you avail yourself of them, and you build your platform in such a way that you avoid tight coupling and increase scalability as much as you can.