Microservices.io is brought to you by Chris Richardson. Experienced software architect, author of POJOs in Action and the creator of the original CloudFoundry.com. His latest startup is eventuate.io, a microservices application platform.
He offers a comprehensive set of resources for learning about microservices including articles, an O'Reilly training video, consulting, workshops and hands on training classes.Learn More
Join the microservices google group
You have applied either the Client-side Service Discovery pattern or the Server-side Service Discovery pattern. Service instances must be registered with the service registry on startup so that they can be discovered and unregistered on shutdown.
How are service instances registered with and unregistered from the service registry?
A service instance is responsible for registering itself with the service registry. On startup the service instance registers itself (host and IP address) with the service registry and makes itself available for discovery. The client must typically periodically renew it’s registration so that the registry knows it is still alive. On shutdown, the service instance unregisters itself from the service registry.
This is typically handled by a Microservice chassis framework
Netflix Eureka is an example of a service registry. It provides a registration API and a client library that service instances use to (un)register themselves.
When using Apache Zookeeper as a service registry, each service corresponds to a particular Zookeeper znode. On startup, each service instance creates an ephemeral child znode of the service znode. The ephemeral znode contains the instance’s location. Clients of the service simply retrieve the children of the service znode in order to determine the available instances. If the client terminates without removing the ephemeral node, Zookeeper will timeout the client and remove the znode.
The benefits of the Self Registration pattern include the following:
There are also some drawbacks: