DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • A New Era Of Spring Cloud
  • API Gateway vs. Load Balancer
  • Architecting for Resilience: Strategies for Fault-Tolerant Systems
  • Preserving Context Across Threads

Trending

  • Why API-First Frontends Make Better Apps
  • Building an AI Nutrition Coach With OpenAI, Gradio, and gTTS
  • The Rise of the Intelligent AI Agent: Revolutionizing Database Management With Agentic DBA
  • 10 Predictions Shaping the Future of Web Data Extraction Services
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Spring Cloud LoadBalancer vs Netflix Ribbon

Spring Cloud LoadBalancer vs Netflix Ribbon

In this article you will learn how Spring Cloud LoadBalancer differs from Netlix Ribbon, and why the first was replaced by the second.

By 
Mario Casari user avatar
Mario Casari
·
Jul. 01, 25 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
2.2K Views

Join the DZone community and get the full member experience.

Join For Free

The Spring Cloud ecosystem has been evolving significantly over the years. At first, it was mainly based on the Netflix stack, then it started shifting towards its own solutions. One of the components that has been substituted is Netflix Ribbon. Ribbon is a client-side load balancer and has been replaced by  Spring Cloud LoadBalancer.

Spring Cloud LoadBalancer is a more modern and maintainable solution. In this article, you will learn the differences between the two, their designs, and practical examples in Java.

Background

Spring Cloud once used Netflix Ribbon for client-side load balancing in its microservices architectures. It provided various load balancing algorithms:

  • RoundRobinRule: Distributes requests sequentially in a circular manner. It is a good choice when the servers have the same capacity.
  • RandomRule: Choose servers randomly
  • AvailabilityFilteringRule: Skips servers that are in circuit-breaker tripped state or have high concurrent connections.
  • WeightedResponseTimeRule: Calculates the average response time and assigns a weight to each server.
  • ZoneAvoidanceRule: Calls zone and servers based on their performance.
  • RetryRule: Retry failed servers after a defined time using one of the other rules.

Netflix officially deprecated Ribbon, and Spring Cloud introduced its own load balancer, a more mature and configurable solution that integrates better with the existing ecosystem, while providing the same algorithms described above.

Architecture Comparison

Ribbon integrates with Eureka for service discovery, maintaining its internal list of service instances. It can define load-balancing strategies with the help of external configuration.

In summary:

  • It's part of the Netflix OSS stack (along with other components like Eureka, Hystrix, Zuul).
  • Integrates well with Eureka
  • Adopted by Spring Cloud in early versions.

Ribbon is based on the ILoadBalancer interface. The implementation of this interface allows the caller to choose from a list of servers, following certain rules. The default implementation is DynamicServerListLoadBalancer. This class works with a dynamic list of servers, keeps track of active server instances, and polls the service registry to keep the list updated.

Ribbon can get its server list from a hardcoded list (for testing use), or from a service registry like Eureka using a DiscoveryEnabledNIWSServerList component.

Spring Cloud LoadBalancer is part of the Spring ecosystem. Because of this, it integrates natively with Spring Boot and Spring Cloud Discovery services such as Eureka and Consul. It can be configured using the same model as Spring Boot. It also supports reactive programming.

  • It is maintaned by the Spring team.
  • It integrates natively with Spring Boot, Spring Cloud, and WebFlux.

The main architectural building blocks of Spring Cloud LoadBalancer are:

  • Spring Cloud DiscoveryClient: It's an abstraction that allows the load balancer to fetch the list of services from registries like Eureka, Consul, Zookeeper.
  • ServiceInstanceListSupplier: An interface which implementation is supposed to supply a list of service instance objects for a given service ID. It can be customized with filters (like zone preference).
  • LoadBalancerClient / ReactiveLoadBalancer: There is a regular load balancer client for interfacing with MVC applications, and a reactive version for use with WebClient or Spring WebFlux.
  • LoadBalancerInterceptor: Serves the purpose of intercepting HTTP requests.
  • ReactorServiceInstanceLoadBalancer: Defines the strategy used by the load balancer. Two built-in strategies are RoundRobinLoadBalancer and RandomLoadBalancer. Custom implementations che be plugged in by providing a bean of type ReactorServiceInstanceLoadBalancer.

Configuration Example With Netflix Ribbon

Ribbon can be configured for interfacing Eureka by puttin some configuration in the application.yml file, and rely on Ribbon's automatic integration.

YAML
 
service-test:  
   ribbon:    
      NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule


In Java, REST calls can be made through RestTemplate annotated with @LoadBalanced

Java
 
@Bean 
@LoadBalanced 
public RestTemplate restTemplate() 
{
  return new RestTemplate(); 
}

//Example
String response = restTemplate.getForObject("http://service-test/endpoint", String.class);


Ribbon handles resolving the name service-test to one of the registered instances through Eureka.

Configuration Example With Spring Cloud LoadBalancer

The same functionality can be implemented with Spring Cloud LoadBalancer by defining a bean annotated with @LoadBalanced:

Java
 
@Bean
@LoadBalanced 
public WebClient.Builder webClientBuilder() 
{    
  return WebClient.builder(); 
}
//Example 
String response = webClientBuilder.build()
  .get()
  .uri("http://service-test/endpoint")
  .retrieve()
  .bodyToMono(String.class)
  .block();


Spring Cloud LoadBalancer integrates with Spring's DiscoveryClient and uses a round-robin strategy by default.

Extending Load-Balancing Behavior

The approach by which Ribbon and Spring Cloud LoadBalancer allow custom strategies differs significantly. Ribbon needs to subclass existing rule classes.

Java
 
public class CustomRule extends RoundRobinRule {
  @Override
  public Server choose(Object key) {
    return super.choose(key);
  } 
}


In Spring Cloud LoadBalancer, you define your own ReactorLoadBalancer.

Java
 
@Bean
public ReactorLoadBalancer<ServiceInstance> customLoadBalancer(Environment env, LoadBalancerClientFactory factory) {
	return new MyCustomLoadBalancer(factory.getLazyProvider("service-test", ServiceInstanceListSupplier.class)); 
}


This provides more flexibility and better support for reactive flows.

Why the Shift?

The transition from Netflix Ribbon to Spring Cloud LoadBalancer was inevitable. It was part of a progressive removal of Netflix OSS components from the Spring Cloud ecosystem. Beside Ribbon becoming deprecated, it also played a role the Spring Cloud's emphasis on maintainability, testability, and native integration.

Spring Cloud LoadBalancer is better aligned with Spring Boot’s principles, has first-class support for both imperative and reactive stacks, and reduces external dependencies. It’s also actively maintained by the Spring team.

Conclusion

Ribbon served its purpose well in Spring Cloud applications for years, but Spring Cloud LoadBalancer is a better, more modern alternative. Its configuration is simplified, follows Spring idioms, and ensures long-term support and extensibility. It also aligns more naturally with Spring Boot’s reactive stack, making it a seamless fit for both blocking and non-blocking applications. Migrating to Spring Cloud LoadBalancer ensures a cleaner, more sustainable implementation of client-side load balancing.

Spring Cloud Load balancing (computing) Architecture

Opinions expressed by DZone contributors are their own.

Related

  • A New Era Of Spring Cloud
  • API Gateway vs. Load Balancer
  • Architecting for Resilience: Strategies for Fault-Tolerant Systems
  • Preserving Context Across Threads

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: