Service registry pattern
Need(s)
With Microservices architecture, for X-axis scaling, we will duplicate instances of our service dynamically. So how to know about the available instances of a service ?
Service registry pattern definition
A service registry is a database of services, their instances and their locations. The interaction between a service and the registry is called registration. The registration can be done in two ways :
Self-registration: it forces services to interact with the registry by themselves. When a service goes up, it notifies the registry. The same thing happens when the service goes down.
Third-party registration: there is a process or service that manages all other services. This process polls or checks in some way which microservice instances are running and it automatically updates the service registry.
Self-registration advantages
More control: service instance knows its own state so it can implement a state model that’s more complex than UP/DOWN.
No forgotten error: we are sure for the registration of every service instance because it register himself.