Back to Microservice Course

Microservice Course

Important: Netflix Ribbon is in Maintenance Mode

Netflix Ribbon was officially placed in maintenance mode in 2018 and is no longer actively developed. The Spring Cloud team replaced it with Spring Cloud LoadBalancer starting in Spring Cloud 2020.0 (Ilford). If you are starting a new project or upgrading an existing one to Spring Boot 2.4+ / Spring Cloud 2020.0+, use Spring Cloud LoadBalancer instead of Ribbon. The concepts below remain valid — understanding client-side load balancing matters regardless of which library implements it — but the Ribbon-specific code and dependencies should not be used in new development.


Client-Side Load Balancing

Load balancing distributes incoming requests across multiple instances of a service to improve throughput, reliability, and availability.

There are two models:

  • Server-side load balancing: An infrastructure component (a hardware load balancer, AWS ELB, or NGINX) sits in front of the service cluster and distributes traffic. The client knows nothing about how many instances exist. Simple for the client, but adds a network hop and a central infrastructure dependency.
  • Client-side load balancing: The calling service (the client) maintains a list of available service instances (fetched from a service registry like Eureka) and selects one for each request using a load-balancing algorithm. No extra infrastructure hop is needed, and the client can implement sophisticated routing logic (availability filtering, zone preference, weighted routing, etc.).

Spring Cloud LoadBalancer (Current Approach)

Spring Cloud LoadBalancer is the actively maintained, non-blocking replacement for Ribbon. To use it, add the spring-cloud-starter-loadbalancer dependency (it's included transitively with spring-cloud-starter-netflix-eureka-client in current Spring Cloud releases).

@Bean @LoadBalanced RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); }

With @LoadBalanced applied, the RestTemplate automatically integrates with Spring Cloud LoadBalancer and Eureka — calls to http://service-name/path are resolved to an actual instance by looking up registered instances in the service registry and applying a round-robin (default) or custom balancing strategy. No additional configuration is needed for the common case.

For reactive (WebFlux) applications, use @LoadBalanced WebClient.Builder instead of RestTemplate.


Legacy: Netflix Ribbon (Maintenance Mode — for reference only)

The Ribbon-specific code below is included for reference and understanding of the concepts, but should not be used in new projects.

Ribbon without Eureka (explicit server list)

billingservice: ribbon: eureka: enabled: false listOfServers: localhost:8091,localhost:8092 ServerListRefreshInterval: 2000
public class RibbonConfiguration { @Autowired IClientConfig ribbonClient; @Bean public IPing ribbonPing(IClientConfig config) { return new PingUrl(); } @Bean public IRule ribbonRule(IClientConfig config) { return new AvailabilityFilteringRule(); } }
@SpringBootApplication @RibbonClient(name = "billingservice", configuration = RibbonConfiguration.class) public class OrderManagementServiceApplication { public static void main(String[] args) { SpringApplication.run(OrderManagementServiceApplication.class); } @Bean @LoadBalanced RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } }

Note: When using Feign Client (OpenFeign), client-side load balancing is handled automatically — no separate Ribbon or LoadBalancer configuration is needed at the method level, making Feign the cleaner choice for service-to-service REST calls in most cases.