Home » Load Balancing with Ribbon

Load Balancing with Ribbon

by Online Tutorials Library

Client-Side Load Balancing with Ribbon

Netflix Ribbon

Netflix Ribbon is a Part of Netflix Open Source Software (Netflix OSS). It is a cloud library that provides the client-side load balancing. It automatically interacts with Netflix Service Discovery (Eureka) because it is a member of the Netflix family.

The Ribbon mainly provides client-side load balancing algorithms. It is a client-side load balancer that provides control over the behavior of HTTP and TCP client. The important point is that when we use Feign, the Ribbon also applies.

Features of Ribbon

  • Load balancing
  • Fault tolerance
  • Multiple protocol support in Asynchronous model
  • Caching and batching

Modules

  • ribbon: It is an API that integrates load balancing, fault-tolerance, caching, and
  • ribbon-loadbalancer: It is a Load balancer API that can be used independently or with other modules.
  • ribbon eureka: It uses Eureka client that provides a dynamic server list for the Spring Cloud.
  • ribbon-transport: It is a transport client that supports HTTP, TCP, and UDP These protocols use RxNetty with load balancing capability.
  • ribbon-httpclient: It is a REST client built on top of Apache HttpClient integrated with load balancers.
  • ribbon-core: It is a Client Configuration API.

Types of Load Balancing:

There are two types of load balancing

  • Server Side Load Balancing: Server side load balancing is a monolithic It applies between the client and the server. It accepts incoming network, application traffic, and distributes the traffic across the multiple backend servers by using various methods. The middle component is responsible for distributing the client requests to the server.
  • Client-Side Load Balancing: The client holds the list of server’s IPs so that it can deliver the requests. The client selects an IP from the list, randomly, and forwards the request to the server.

Let’s configure the Ribbon server in our project.

Step 1: Go to the project currency-conversion-service.

Step 2: Open pom.xml file and add the ribbon dependency.

After adding the dependency, we need to enable ribbon on the proxy.

Step 3: Open the CurrencyExchangeServiceProxy.java file. Enable Ribbon by adding an annotation @RibbonClient and specify the name of the service which we want to talk to. Ribbon client provide the declarative configuration for a client.

CurrencyExchangeServiceProxy.java

Step 4: In the annotation @FeignClient, remove the attribute URL. Because we do not need to talk with one particular service. We will configure that URL in the application.properties file.

Step 5: Open the application.properties file of the project currency-conversion-service and configure the servers. The property that we have to configure is:

We have configured the two instances of currency-exchange-service that we want to invoke.

application.properties

Running Client Side Load Balancing with Ribbon

We have two instances of CurrentlyExchangeServiceApplication.java, as shown in the following image:

Client-Side Load Balancing with Ribbon

First, run the CurrencyExchangeServiceApplication on port 8000 and then run the CurrencyExchangeServiceApplication on port 8001.

After running the CurrencyExchangeServiceApplication on both the ports, run the CurrencyConversionServiceApplication.java by sending the request http://localhost:8100/currency-converter-feign/from/EUR/to/INR/quantity/10000. It returns the following response.

Client-Side Load Balancing with Ribbon

In the above image, the port 8000 represents that the currency-exchange-service is running on port 8000 and handling the current request.

Now, refresh the page. We get the same response except for the port number and quantity because we have changed the quantity in the request.

Client-Side Load Balancing with Ribbon

In the above image, the port 8001 represents that the currency-exchange-service is running on port 8001 and handling the current request.

Let’s understand the load balancing through a figure:

Client-Side Load Balancing with Ribbon

In the above figure, Ribbon is distributing the load between three active CurrencyExchangeServices. The CurrencyExchangeService1 is running on port 8000, and CurrencyExchangeService2 is running on port 8001, and so on. So whatever calls are made using Ribbon through the CurrencyCalculationService, are distributed among these three services.


You may also like