Tuesday, March 17, 2020

Microservices Interview - 2 : Client Side Discovery/Server Side Discovery

Microservices Interview - 2 : Client Side Discovery/Server Side Discovery


As, we know, services need to call one another. In a monolithic application, services invoke each other through language-level method or procedure calls.

In a traditional distributed system deployment , services run at fixed, well known locations, so can easily call one another using REST API or some RPC mechanism.

However a microservice-based application runs in a virtualized or containerized environments  where the number of instances of a service and its locations change dynamically.

So, the problem is:

How does the client service - API Gateway or another service - discover the location of a service instance?

Forces:

  • Each instance of a service exposes a remote API such as HTTP/REST at a particular location.
  • The number of service instances and their location change dynamically.
  • Virtual machines and containers are usually assigned dynamic IP addresses. 

Solution:

Client Side Service Discovery:

When making a request to a service, the client obtains the location of the service instance by querying a service registry, which knows the locations of all service instances.

  





So, in Client Side Service discovery, Client service - API Gateway send request to Service registry to find a service and then load balance the request to any instance of that service.



Server Side Service Discovery:





In server side service discovery, client service - API Gateway sends request to a Router a.k.a. Load Balancer which in turn send a query to service registry ,finds the service and propagates request to appropriate instance.
  


Benefits of server side service discovery:

  • Compared to client side discovery, the client code is simpler since it does not have to deal with discovery. Instead, a client just makes a request to the router.
  • Some cloud environments provide this functionality , e.g.: AWS Elastic Load Balancer.







No comments:

Post a Comment

CAP Theorem and external configuration in microservices

 Hi friends, In this post, I will explain about CAP Theorem and setting external configurations in microservices. Question 1: What is CAP Th...