How ServiceInstanceListSuppliers is connected with Eureka server to get the registry list of microservices?





Spring Cloud LoadBalancer and Eureka


How ServiceInstanceListSuppliers Connects to Eureka

🔗 Overview

In a Spring Cloud microservices architecture using Eureka and Spring Cloud LoadBalancer, service discovery and load balancing involve the following flow:

  1. The Eureka Client registers services with the Eureka Server.
  2. The client keeps a local cache of the registry information from the server.
  3. Requests made via RestTemplate, WebClient, or Feign (annotated with @LoadBalanced) trigger Spring Cloud LoadBalancer.
  4. Spring Cloud LoadBalancer calls a ServiceInstanceListSupplier to get the list of available service instances.

🧩 Role of ServiceInstanceListSuppliers

ServiceInstanceListSuppliers provides the list of service instances to Spring Cloud LoadBalancer. When Eureka is used, the implementation is:

org.springframework.cloud.netflix.eureka.EurekaServiceInstanceListSupplier

This class connects LoadBalancer to the Eureka registry using the DiscoveryClient.

🔄 Flow of Interaction

  1. Request is made to a service.
  2. LoadBalancer intercepts and asks for service instances.
  3. ServiceInstanceListSupplier.get() is invoked.
  4. EurekaServiceInstanceListSupplier uses Eureka’s DiscoveryClient to fetch instances.
  5. Instances are returned from the local cache.

📦 Code Example

@Override
public Flux<List<ServiceInstance>> get() {
    return Flux.defer(() -> {
        List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);
        return Flux.just(instances);
    });
}

⚙️ Auto-Configuration

  • If spring-cloud-starter-netflix-eureka-client is on the classpath,
  • And @EnableDiscoveryClient is used,
  • Then EurekaServiceInstanceListSupplier is auto-configured as the default implementation.

✅ Summary

Component Role
Eureka Server Holds the registry of available services
Eureka Client (DiscoveryClient) Syncs with server and caches the registry
ServiceInstanceListSupplier Supplies instances to the LoadBalancer
EurekaServiceInstanceListSupplier Bridges LoadBalancer and Eureka using DiscoveryClient
Note: The LoadBalancer queries Eureka’s local cache, not the server directly, to reduce latency and improve resilience.


Leave a Comment

Your email address will not be published. Required fields are marked *