springspring-bootspring-cloudnetflix-eurekaspring-cloud-netflix

What is the default load balancing mechanism used by Spring Cloud Eureka and is there a way to modify it?


I understand that Eureka is meant for service discovery, but what if I have multiple instances running for the same service registered in eureka server?

Let's say I have three instances registered in Eureka server for the same service. Then, If I consume the service, I get random instances returned from Eureka.

Does this mean Eureka uses random approach for load balancing? If yes, is it possible to modify it to use round-robin approach?


Solution

  • Default is ribbon and it can be disabled as below

    spring.application.name=client
    spring.cloud.loadbalancer.ribbon.enabled=false
    

    this then defaults to Spring Loadbalancer where you can create custom @LoadBalancerClient and pass your own config

    more on it here https://spring.io/blog/2020/03/25/spring-tips-spring-cloud-loadbalancer