Server Side Load Balancing With Netflix Zuul and Eureka

Server Side Load Balancing With Netflix Zuul and Eureka:-

In this post, we will talk about server-side load balancing With Zuul and Eureka. Let us take a while and understand what is meant by server-side load balancing. In simple word, we distribute our user requests.In a Spring Cloud MicroServices ecosystem load balancing is an important and common functionality .

Zuul acts as a gateway for requests from websites, mobile devices to the backend of your service. Zuul is an edge service that provides dynamic routing, monitoring, resiliency, security, and many more features.

1.Why Do We Need Zuul:-

The amount of high traffic sometimes results in complex production issues. We want a system that can rapidly react to these changes. This technique was used when a new page from the website needed tuning for a smaller set of mobile devices or a group of customers.




If Performance problems, as well as unexplained errors, were observed. It was difficult to debug the issues because the problems were only happening for a small set of customers or a small set of devices. By diverting the traffic to a single instance, it becomes easier to debug in real time. It is done using Zuul filters in a netflix Zuul Load balancer. Zuul uses different types of filters that we can implement for various purpose, read more about this here.

2.Project Setup:-

We are going to set up and run three projects.

  1. Eureka Service Discovery – Service Registry for Our Backend Services. Please have a look at our previous example about Creating Eureka Service Discovery.
  2. Customer Service – A rest API which is basically a backend service in a real-time scenario. Visit my previous post about Writing  Service Rest With Spring Boot.
  3. Zuul Gateway – API Gateway to serve requests and call our internal backend services.in this case, it acts as a proxy and calls our customer service Internally.

3.Configure Zuul Communicating With Eureka:-

Now we have to Configure our  Zuul to Communicate with Eureka Server and mark our application as Zuul Proxy . To do this we need to use @EnableZuulProxy  annotation  in our main application file.

Add the following configuration in your  application.yml file.

Here we are registering our proxy server to Eureka service Registry assuming eureka running on 8761 port. Our Proxy Server will run on 8060.

We also configured routes for our Zuul proxy. We already have our customer service registered with Eureka Registry. Hence we now have just configured the routes to access the customer service.customer-service the name of the service we registered.

Once Zuul receives a request for a particular service , it internally uses Netflix Ribbon to lookup for services available from Eureka Service Discovery.

We can run multiple instances of our rest service and our API gateway will use both of the instances in round robin fashion.

 

Testing Zuul Eureka Service Discovery:-

 

 

 

 

Leave a Reply

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