Service discovery pattern
With Microservices architecture, for X-axis scaling, we will duplicate instances of our service dynamically. So for inter-process communication, how does one service knows about the location of an instance of a second service ?
Service discovery pattern definition
A service discovery is a mechanism that enables the clients of service to make requests to a dynamically changing set of ephemeral service instances. The interaction between a client and the service is called discovery.
The discovery can be done in two ways :
- Client-side discovery: The client is responsible for determining the network locations of available service instances and load balancing requests across them. The client queries a service registry, which is a database of available service instances. The client then uses a load‑balancing algorithm to select one of the available service instances and makes a request. The Client-side discovery have some advantages like fewer moving parts and less network hops. Using that implies Registry first bootstrap - every service needs to know about the registry service URI from its local configuration file.
- Server-side discovery: The client makes a request to a service via a router. The router queries the service registry and load balances each request to an available service instance. As with Client-side discovery, service instances are registered and deregistered with the service registry.