Search code examples
springmicroservicesnetflix-eurekanetflix-ribbon

How Ribbon retrieves the list of available instances of a service


I am using ribbon as a load balancer on API gateway and eureka server. When a client request comes to my API gateway, does it query the service registry each time to obtain the available instances of a service, or does Ribbon store the available instances into its cache?


Solution

  • Spring Cloud Ribbon talks to discovery client for getting information about running instances of a given service. Discovery client keeps an in-memory cache of eureka registrations, to make lookup faster.

    You can have a look at the Spring Cloud Netflix documentation for more information:

    https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-eureka-server.html

    The Eureka server does not have a back end store, but the service instances in the registry all have to send heartbeats to keep their registrations up to date (so this can be done in memory). Clients also have an in-memory cache of Eureka registrations (so they do not have to go to the registry for every request to a service).

    Also, for Ribbon with Eureka: https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-ribbon.html#_using_ribbon_with_eureka

    When Eureka is used in conjunction with Ribbon (that is, both are on the classpath), the ribbonServerList is overridden with an extension of DiscoveryEnabledNIWSServerList, which populates the list of servers from Eureka.

    The clients from any zone can look up the registry information (happens every 30 seconds) to locate their services (which could be in any zone) and make remote calls. Fore more information, please visit Official Netflix Eureka Documentation