Service Discovery in Microsrvice

Service Discovery Problem
  • Service Registration: The process of a service registering its location to central registry. Usually, It register its host and port and may also authentication and environment details.
  • Service Discovery: The process of a client get information from central registry to know about the location of services.

The Client Side Discovery Pattern

The client determine the network locations of service instance by querying a service registry and It can use a load balancing algorithm to select which service instances to makes a request.

  • Service instant send register request with its network location to the service registry when it startup.
  • Service instants will be removed from the service registry when it terminates.
  • Service register is heartbeat mechanism to get status of service registration.
Client Side Discovery Pattern

The Server Side Discovery Pattern

When using Server side discovery, Clients just simply make requests to a service instance via a load balancer. The load balance will take the role of client in client side discovery pattern in service discovery and load balancing [Fawad Khaliq, “Fernando Sanchez, Service Discovery and Registration in a Microservices Architecture”, PLUMgrid, 2016]. The following diagram shows the structure of Client Side Discovery Pattern.

Server Side Discovery Pattern

The Service Registry

As mentioned earlier, the service registry is a key part of service discovery. It is a database containing the network locations of service instances. Database of service registry need to be up to date. Clients can cache network locations learned from the service registry to improve performance. A service registry should be configured as a cluster of servers for high availability and need to use a replication protocol to maintain consistency data among servers in cluster.

The Self Registration Pattern

A service instance is responsible for registering and deregistering itself with the service registry. A service instance also sends heartbeat requests to prevent its registration from expiring. The following diagram shows the structure of self registration pattern.

The structure of self registration pattern

The Third Party Registration Pattern

When using this pattern, service instance does not involve to register or deregister it to service register, Another system component, the service registrar handles the registration. The service registrar tracks changes of instances status by subscribing the deployment environment events (deployment, termination, scaling) and detect the instance crash by healthcheck mechanism. The following diagram shows the structure of third party registration pattern:

The structure of third party registration pattern

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
James

James

Network/VoIP Engineer, Python Developer & Photographer.