Centralized Service Registry

Haci Simsek
4 min readApr 5, 2024

--

The world of microservices is growing and evolving with each passing day. If we were to mention one of the biggest advantages of using microservice, it would be their ability to scale up and down under load. However, this dynamism leads to infrastructural complexities. In this article, we will delve into the topic of Service Registry, which is one of the solutions to this complexity. While learning about Service Registry, we will also touch upon the service discovery pattern.

Imagine dynamically increasing and decreasing instances of microservices that need to recognize each other in order to communicate with each other. This is where the service registry comes into play. The service registry discovers and registers newly created instances of services and provides us with a dynamic structure. Let’s define what a service registry is.

What is a Service Registry?

A service registry is an architectural pattern and software component used in microservice architecture. Essentially, a service registry is a service registration and discovery mechanism. It is responsible for storing the computer addresses and connection points where instances of services are located. This information enables services to dynamically discover and communicate with each other. There are many service registries; some of them include Netflix Eureka, Apache ZooKeeper, and Consul. The most popular and widely used one is Netflix Eureka Service Registry.

What is Service Discovery?

Service Discovery is a discovery mechanism that involves the automatic discovery of services within a network and determination of their locations. It can be used as part of a service registry or as a separate tool. Service discovery can be examined under two headings: Client-side discovery and server-side discovery.

Client-side discovery

In this structure, the client directly fetches the IP addresses of active microservice instances from the service registry. It decides which one is available using a load balancing algorithm. Here the client communicates directly with the microservice.

https://www.nginx.com/blog/service-discovery-in-a-microservices-architecture/

Server-side Discovery

In this structure, the client doesn’t directly communicate with the microservice’s instances; instead, a load balancer or an API gateway is placed in between. The client sends its request to the load balancer or API gateway, which then shares the domains of the service instances dynamically registered in the service registry with this intermediary module. Then, the load balancer or API gateway forwards the client’s request to the relevant service.

https://www.nginx.com/blog/service-discovery-in-a-microservices-architecture/

Advantages,

  1. Service discovery in a dynamic structure
  2. Load balancing
  3. High accessibility
  4. Scalability

Disadvantages,

  1. Single point of failure
  2. Security risk
  3. Performance impact
  4. Management complexity

Implementation of Service Registry and Service Discovery

In our application, we will use Netflix Eureka Service Registry. We will have multiple microservices, some of which will have multiple instances. Our application will be a quiz application. And we will use an API gateway to implement the service-side discovery pattern.

This is our pom file of service registry.

In this case, we are using the EnableEurekaServer annotation.

This is our application.properties file of service registery.

As you can see in the image above, there are two microservices. And some of them have more than one instances.

The following link to view the complete code.

Imagination is more important than knowledge. For knowledge is limited, whereas imagination embraces the entire world. — Albert Einstein

In our article, we addressed the important topic of service registry for microservice architecture. Additionally, we covered service discovery topics and later observed this in practical terms at the code level. In this rapidly evolving world, problems and solutions emerge successively. The service registry pattern is one solution to these problems.

Resource

--

--