Intent

This pattern provides guidelines for grouping services together or isolating them from one another for deployment purposes driven by constraints.The Service Consolidation pattern is also known as Service-to-Host Mapping and the Service Partitioning/Segregation pattern.

Context and problem

Let’s assume we have written our service, and it is ready to be deployed. The service may be composed of submodules such as contracts, routes, domain model, persistence layer, configurations, and other layers needed for this service to function as a whole. It can be a very granular microservice with one operation or a monolithic application with a large number of endpoints and operations. All of these artifacts represent the static build time structure of the application and not the runtime view. At runtime, this service may be deployed together with other services in one container (JVM), or perhaps in an isolated container with other containers on the same host (VM), or in a totally isolated host. In addition, the same service may be deployed differently in different environments: from heavily consolidated in development environments to fully segregated in production environments. In certain situations, service deployment may vary temporarily (for example, scaling up or down a service based on the load) or be based on tenancy considerations (a different number of instances deployed for different tenants). All of these deployment models require the application to be written in a way that allows deployment time flexibility and some analyses of the runtime constraints.

Forces and solution

A few well-known deployment models have clear benefits and drawbacks, but finding the right balance for our situation will require analyzing the application’s runtime behavior and other constraints. First, we will look at the different deployment options and then the driving forces behind each of them.

Single service per host

With the term host, we will be referring to an OS regardless of whether it is physical or virtual, in the cloud or on-premises. With this model, there is only one service running per host, and there are many benefits of using this.

Get hands-on with 1200+ tech skills courses.