The original address: microservices. IO/patterns/se…

background

If you use client-side service discovery or server-side service discovery, the service needs to register the instance with the registry when it is started and unregister with the registry when it is shut down for other services to be aware of.

The problem

How do service instances register or unregister with the registry?

consideration

  • The service must register instances with the registry when it is started and unregister instances with the registry when it is shut down
  • Crashed service instances must be unregistered from the registry
  • Instances that are running but cannot provide services properly also need to be unregistered in the registry

The solution

Introduce a third-party registration agent that is responsible for registering and unregistering service instances in the service registry. When a service instance is started, the registration agent registers the instance with the registry. When a service instance is closed, the registration agent is responsible for unregistering the instance.

For example,

Examples of third-party registration patterns include:

  • Netflix Prana, used for non-JVM registrants on Eureka, is no longer updated
  • AWS automatically expands groups and registers EC2 instances to AWS load balancers.
  • ContainerPilot, which runs in the Docker container as the parent of the service and registers it in the registry.
  • Registrator is responsible for the registration and deregistration of Docker containers to various registries
  • Service instances of container choreography frameworks such as Kubernetes and Marathon have built-in implicit service registries

Results analysis

Benefits of the third-party registration model include:

  • The code for the service is simpler than using self-registration mode because it does not take care of registration
  • The registration agent can perform health checks on service instances and register/unregister instances based on their health status.

There are also some disadvantages:

  • The registration agent has only a vague understanding of the state of the service instance, such as only UP and DOWN, and may not know whether it can handle requests properly. Some registration agents, such as Netflix Prana mentioned above, utilize health checks to determine the availability of service instances.
  • An additional registration agent service needs to be maintained, and it needs to be highly available.

Related patterns

  • Registry – the core of service discovery
  • Client service discovery and server service discovery
  • Microservices Infrastructure – Most microservices infrastructure frameworks have self-registered functionality implementations
  • Self-registration – another alternative design pattern