28

I have trouble understanding the connection between Zuul and Ribbon.

I think I got Zuul clear. It's a reverse proxy I can contact to reach one of my several instances of a service. It will pick the right server using a round-robin algorithm or whatever you configure it to do. It's a traditional load-balancer. To know the instances available it can use a registry like Eureka.

But I've got more trouble with Ribbon. It's sold as a client-side load balancer but what does it mean ? It doesn't need an external server ? Ribbon is embedded in the client the same way an Eureka client is ? If so how does it work ? Do I need Zuul when I use Ribbon, and vice-versa ?

On some articles, I saw that in fact, Zuul uses Ribbon by default for the load balancing part and it got me even more confused. If this is true what does "client-side" mean ? What does Zuul do except routing ?

I hope you can help me.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
VanesBee
  • 616
  • 1
  • 6
  • 18

1 Answers1

43

Client and Server is always relative. Zuul is a client for your service instances and your service instances are servers for Zuul.

When we are using traditional load balancer (server-side load balancer), API caller (client) only knows a single endpoint that is a load balancer and the client doesn't know the list of servers. Load balancer chooses a server from the list.

When we are using client-side load balancer like Ribbon, API caller (client) should know the list of servers and choose one of them from the list. That's why we call it client-side load balancer.

As you know, Ribbon is a client-side load balancer module and is integrated to many http client modules. As an example, Feign and Load-balanced RestTemplate support Ribbon. Namely Feign and Load-balanced RestTemplate can choose a server from the given list or the list from eureka when used with ribbon.

Regarding Zuul, there is a RibbonRoutingFilter that routes your request to an actual service instance. RibbonRoutingFilter is using Ribbon to choose a server from the list that is given from your configuration or from Eureka. So if you want to use Zuul as a load-balanced reverse proxy, Zuul needs Ribbon.

chesh
  • 742
  • 8
  • 22
yongsung.yoon
  • 5,489
  • 28
  • 32
  • So am i correct in saying that all you need to do in order for zuul to load balance between eureka-registered running instances of a service is to have zuul-server application.properties file contain the eureka.client.serviceUrl.defaultZone property ? – xpz Mar 29 '20 at 03:09
  • i.e. you use ribbon without having ever the need to even mention it because ribbon is bundled inside of zuul ? – xpz Mar 29 '20 at 03:13
  • @xpz: Yes you are correct. Ribbon is a transitive dependency when you have Zuul in your pom.xml or gradle.build file. When you run the below command you will see Ribbon being added Maven: mvn dependency:tree Gradle: gradle dependencies – Andy May 28 '20 at 22:12