Service Discovery in Microservices

Service Discovery in Microservices

Service Discovery is the automatic detection of devices and services offered by these devices on a computer network. In a microservices architecture, where there might be dozens or even hundreds of services, it is essential to know what services are available and how to communicate with them. Service Discovery solves this problem by maintaining a registry of available services, their instances, and their locations (Ip addresses, or ports..).


There are two types of service discovery

1.The Client‑Side Discovery

When using 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.

2.The Server‑Side Discovery

The client makes a request to a service via a load balancer. The load balancer queries the service registry and routes each request to an available service instance. As with client‑side discovery, service instances are registered and deregistered with the service registry.


The Service Registry

The service registry is a key part of service discovery. It is a database containing the network locations of service instances. A service registry needs to be highly available and up to date. Clients can cache network locations obtained from the service registry. However, that information eventually becomes out of date and clients become unable to discover service instances. Consequently, a service registry consists of a cluster of servers that use a replication protocol to maintain consistency.

Netflix Eureka is good example of a service registry. It provides a REST API for registering and querying service instances. A service instance registers its network location using a POST request. Every 30 seconds it must refresh its registration using a PUT request. A registration is removed by either using an HTTP DELETE request or by the instance registration timing out. As you might expect, a client can retrieve the registered service instances by using an HTTP GET request.


To enable the service discovery, we annotate the discovery server class with @EnableEurekaServer

The application.yml (or application.properties) file for the configuration.

(Note: Moto of this article is to tell you about functional overview of Service Discovery in Microservices environment will see implementation some other day 😅)

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics