Service Instance Pattern
Learn the Service Instance design pattern and its usage.
Intent
This pattern accommodates increasing workloads by distributing the loads on multiple service instances. The Service Instance pattern is also known as Service Load Balancing.
Context and problem
The quality attributes of a software system are non-functional properties driven by the system’s architectural constraints. There are many quality attributes, and their priorities vary largely from project to project. The following are almost always present:
-
Availability is the proportion of time that all system components are fully functional and operational. It is measured as a percentage of the total system downtime over a fixed period.
-
Scalability is the ability of a system to handle increases in the load without impacting the performance.
An application can be scaled vertically or horizontally. Vertical scaling (scaling up) is achieved by adding more resources to a single node in a system to give greater capacity to this node. This way of scaling is limited by the amount of CPU/RAM that can be added to a single host. There is another way of increasing the capacity of a system that can be achieved with commodity hardware (rather than supercomputers) called horizontal scaling. Vertical scaling increases the capacity of a single node, but it does not decrease the overall load on the nodes. Horizontal scaling (scaling out), on the other hand, increases the number of nodes in a cluster and reduces the load on the individual nodes. In this setup, each node has the same capacity, but the load on the nodes is decreased as it spreads across more nodes. While vertical scaling is easier, it is more expensive and with a limited reach. On the other hand, horizontal scaling is cheaper (from a hardware point of view) but harder to implement and sometimes not even possible. The Service Instance pattern results from applying horizontal scaling principles to the application layer.
Forces and solution
Starting multiple instances of a service and distributing the load to all instances allows us to increase the system’s overall capacity and achieve high availability through redundancy and avoiding a single point of failure. There are a few areas to consider before implementing the Service Instance pattern that we will look at in this section.
-
Service state: Ideally, in the SOA and integration world, we want to have stateless services whenever the business requirements allow it. But what exactly is a stateless service in this context? This is not a kind of service that does not interact with an external state (such as a database) or a service with no local state (local variables for processing a request). Instead, it is a service that does not maintain any state between different service calls if all the service data used to process a request (temporarily created local data, thread context, etc.) is discarded or persisted to an external service data store. In such a case, if the subsequent service calls go to a different thread or process instance running the service, the request is processed successfully.
The main benefit of stateless services is that they are ...