Service Discovery

  • Auto scaling is a technique Where we automatically and dynamically scale our services to meet varying levels of demand.
  • When we have multiple instances of an application service, there will be a load balancer to manage the request and forward it to any of the instances.
  • In case where Auto scaling or manual scaling has to happen that is the instances can be added or decreased depending on demand. Their IP Will change.
  • The load balancer needs to be Aware of the new IP addresses or new instances.
  • Any time, any kind of happens or deployment takes place, the IP will change.
  • Service registry pattern is used to solve the above problem.
  • Service Registry stores the mapping between the service and its corresponding instances.
  • Whenever a request comes to load balancer it checks for service registry for different IP’s of a service.
    • The load balancer may also cache the above data somewhere.
  • Thus it would know where it has to route the request.
  • When new instances are added, they will Register themselves with Service Registry.
  • Now Next time, when the request comes to the Load Balancer, It will check the service registry again for routing. this time it will get increased number of instances where the request can be routed.
  • Above process is called as server side discovery because on server side, the discovery is happening.
  • The server side is responsible to figure out from service, where are my instances and what are the map and host names of those instances.
  • We also have client side discovery, the client talks to the service registry and getting respective IP’s Or host names.
    • The service registry in this case might store the IP’s of the Load balancer as well.
    • There may be a case where load balancer is totally removed from the picture and client service itself will have the routing mechanism/logic built at the client side.
    • Client service can also cache The data from the service registry in order to be efficient so that it does not have to make an extra call every time.
  • In Majority of cases, this responsibility is offloaded to the server side rather than the client side and the client side is kept free from this kind of responsibilities
  • Services may register themselves to the service registry as a part of their spin up so that as soon as service instance comes up, it will have the responsibility to make A call to the service registry and get itself entered in the registry.
  • There can be some third-party tools, which the instances can call in order to get registered to the service registry.
  • Service registry can be a single point of failure if we look at Service registry either on server side or on client side, and if the service registry goes down, there will be a failure.
  • One way to handle this is to cache The values we get from service registry so that we have some kind of availability, and there is not 100% failure.
  • We should also keep in mind if we are building a service, registry it is a component That should be highly available. It cannot afford to fail.

No comments:

Post a Comment

Spring Boot

What is circular/cyclic dependency in spring boot? When two services are interdependent on each other, that is to start one service, we requ...