Hazelcast IMDG server processes are easily wrapped by Spring Boot for simple deployment, monitoring, and the like. As Java processes, they could easily also be microservices.
In general, this would be a bad idea. In specific cases, a very good idea.
The reasons follow, and while none are individually significant, there are more arguments for using Hazelcast IMDG’s client-server topology then embedding the Hazelcast IMDG server in the same process as the microservice.
Simplicity
A microservice instance that embeds a Hazelcast IMDG server makes for less processes to deploy.
If the architectural ideal that each process runs on a machine dedicated to it is affordable, then fewer modules require fewer hardware resources.
Scaling
The microservice might need a certain number of instances to cope with demand, and the Hazelcast IMDG grid needs a certain number of instances for capacity.
It is unlikely these two numbers start the same and stay the same. In client-server mode, they could be varied independently, but when embedded, the larger number applies to both. While some spare capacity is sensible, excessive spare capacity is wasteful of resources.
Separation of Concerns
Data stored in a Hazelcast IMDG server is striped horizontally to give an even balance.
If there are three Hazelcast IMDG servers, then each holds one-third of the data. This could be one-third of the data for microservice A and one-third of the data for microservice B.
![Image title](/storage/temp/6431680-image5.png)
If this Hazelcast IMDG server is embedded in microservice A, then this violates the separation of concerns tenet for microservices. Simply, microservice A is not isolated from the data for other microservices.
![Image title](/storage/temp/6431687-image6.png)
Rolling Upgrades
Fault tolerance is one of the usual goals of microservices. One or all of the instances of a microservice should be able to go offline, and other microservices should be able to continue operating. If they can’t, that’s usually an indicator that service isolation is not correctly designed.
This normally allows the total outage option when a microservice has to be upgraded. All instances of a particular microservice can be taken offline for upgrade, as all other microservices should continue to operate.
However, if the microservice embeds Hazelcast IMDG server and therefore data, taking a total outage on the microservice means a total outage on the Hazelcast IMDG grid. Being “in-memory” storage, contents are lost and would have to be reloaded.
To avoid this would require a rolling upgrade strategy for the microservice with the embedded Hazelcast IMDG server. This makes for a longer upgrade to do processes individually. During the rolling upgrade, both old and new versions of the microservice are live, which is an extra complication to accommodate.
Security
Proper security of data access is not possible if the data accessor (the microservice) and the data storage (Hazelcast IMDG server) exist in the same process.
Although Hazelcast IMDG can provide role-based authorization and access control, if the microservice is in the same process, it could cheat by looking in the process memory, bypassing any controls.
Java
The Hazelcast IMDG server is Java-based. If this is hosted in the same process as the microservice, then that process has to be a JVM.
This forces the microservice to be a JVM compatible language, such as Java.