These are chat archives for spring-cloud/spring-cloud

2nd
Aug 2018
CH4:D
@chad_d_stud_twitter
Aug 02 2018 03:04
not sure if this is a valid question. suppose i have multiple instances of a zuul gateway. is there a sample implementation i can see as to how to configure a web page to cycle through those gateways? or am i seeing this wrong?
Marcos Barbero
@marcosbarbero
Aug 02 2018 06:45
Hi @chad_d_stud_twitter can you elaborate a little? I'm not sure about what you are asking
ManuelDeveloper
@manueldeveloper
Aug 02 2018 06:52
I'd like to add something to the conversation that you had @bilalahmed54 and @marcosbarbero. Spring Cloud Gateway doesn't any balancing between nodes by itself, it delegates that to your discovery-service (Eureka, Consul, etc). Zuul, on the other hand, balances by itself because includes Ribbon in its stack (if you use Spring-Cloud-Netflix obviously).
Marcos Barbero
@marcosbarbero
Aug 02 2018 07:03
that's not correct @manueldeveloper
neither Eureka nor Consul has load balancing logic, briefly speaking it gives to the gateway a simple map containing the services and its available instances and the gateway, either spring cloud netflix zuul or spring cloud gateway, uses some sort of client side load balancer in which makes the decision which node to route the request.
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 07:45
@marcosbarbero @manueldeveloper
I just made an experiment. I just created an Eureka server and registered two Eureka clients with it with same name. Then, I implemented a discovery client (using RestTemplate) which discovered client from Eureka server and invoked its API and I can see that its invoking APIs in round robin fashion, from both registered clients one-by-one. Now, apparently, it looks that Eureka server is doing this? Because I didn't use Spring cloud Ribbon component then who's doing this load-balancing stuff?
P.S. I didn't involve any API gateway yet.
And experienced the same behaviour with Feign client as well that APIs from both clients being called one-by-one in round robin fashion.
Marcos Barbero
@marcosbarbero
Aug 02 2018 07:54
Again, there’s no load balancing logic implemented in eureka. If you are using load balanced resttemplate it’s the restTemplate doing it, if I’m not mistaken it uses ribbon under the hood to apply the load balancing strategy
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:09
EurekaClient :: getNextServerFromEureka
Documentation: Gets the next possible server to process the requests from the registry information received from eureka. The next server is picked on a round-robin fashion.
So, it seems, its Eureka Clients who's doing load balancing here?
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:23
well the class EurekaClient has no such method, what does have it is the class DiscoveryClient, but as you said previously you are using RestTemplate and it's completely different. It's using an implementation of LoadBalancerClient, most likely to be RibbonLoadBalancerClient in which uses the interface ILoadBalancer to pick the server.
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:26
Yes, I tried with both RestTemplate and Feign which gave me the same load balancing behaviour.
Below is the code snippet that how eureka client is discovering client from server with built-in round robbin fashion:
@Autowired
private EurekaClient eurekaClient;
InstanceInfo instanceInfo = eurekaClient.getNextServerFromEureka("eureka-service-client", false);
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:28
it's more readable if you format your code to post it here
yeah, indeed... EurekaClient interface extends the LookupService interface in which has this method
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:34
And this is how I'm achieving this using Feign:
@FeignClient(name = "eureka-service-client")
public interface IEurekaServiceClientInterface {
}
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:34

But what I mean with

there’s no load balancing logic implemented in eureka

is that there's no such logic in eureka server, and as I also said the gateway (or whatever) uses some sort of client side load balancing in which is eureka client in this case.

Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:35
So, in both scenarios, using Feign and using EurekaClient in RestTemplate implementation, I'm getting round robbing load-balancing thing.
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:35

I just don't follow what you mean by

using EurekaClient in RestTemplate implementation

are you using RestTemplate or EurekaClient?
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:37
using both, below is the full implementation:
    @Autowired
    private EurekaClient eurekaClient;
    @Autowired
    private RestTemplateBuilder restTemplateBuilder;
    @RequestMapping("/")
    public String invokeService(){
        RestTemplate restTemplate = restTemplateBuilder.build();
        InstanceInfo instanceInfo = eurekaClient.getNextServerFromEureka("eureka-service-client", false);
        String serviceBaseUrl = instanceInfo.getHomePageUrl();
        return restTemplate.getForObject(serviceBaseUrl, String.class);
    }
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:39
well, that's not exactly how you should be doing it
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:39
EurekaClient gives me the client instance info and RestTemplateBuilder invokes service of that client. I hope its clear now.
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:39
you can, but there's a better way to achieve the same behaviour
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:39
Would be good, if you suggest that
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:40
it's pretty simple actually, you won't need to do all the build stuff
if you follow this https://spring.io/guides/gs/client-side-load-balancing/ you will figure out quite a few ways to do client side load balancing
feign, ribbon, load balanced restTemplate and maybe more, I don't really recall
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:45
okay, great. I'll look into this. So, if we conclude our discussion, @FeignClient and EurekaClient gives out of the box support of load balancing (as I showed in the previous code snippets) without explicitly using ribbon may be its being used behind the scene by Feign and Eureka Client.
CH4:D
@chad_d_stud_twitter
Aug 02 2018 08:47
@marcosbarbero i want to have multiple instances of my zuul gateway running for redundancy. how do i configure my frontend about these gateways?
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:47
@bilalahmed54 case closed :smile:
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:48
@marcosbarbero I hope I got you right and concluded correctly :)
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:48
@chad_d_stud_twitter do you wanna have a cluster of zuul for the frontend to call, is it?
CH4:D
@chad_d_stud_twitter
Aug 02 2018 08:48
yes
but if i’m seeing it wrong, that’s okay
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:51
I do believe we both learned things today @bilalahmed54 , I wasn't that clear at first stating that I was referring to the eureka server. The Eureka Client is also a client side load balancer, in which does the round robin as Ribbon, Feign and RestTemplate, and maybe they all rely on ribbon to do so but I'm not sure about the implementation details of all of them.
it depends a little on your architecture and how's frontend app @chad_d_stud_twitter is it a pure FE app?
CH4:D
@chad_d_stud_twitter
Aug 02 2018 08:52
yes
javascript?
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:52
yeah, javascript, typescript, whateverscript :D
CH4:D
@chad_d_stud_twitter
Aug 02 2018 08:52
they’re most likely using ajax calls to my rest services
Bilal Ahmed Yaseen
@bilalahmed54
Aug 02 2018 08:53
@marcosbarbero Yeah, thanks for your time (y)
CH4:D
@chad_d_stud_twitter
Aug 02 2018 08:53
i just want to toy with the idea that they have failovers
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:53
you are welcome @bilalahmed54
so @chad_d_stud_twitter I'm trying to figure out your architecture design

is it something like this?

FE → Zuul → Downstream Services

CH4:D
@chad_d_stud_twitter
Aug 02 2018 08:54
yes
i just want to know if it’s possible FE -> Zuul01 | Zuul02 | Zuul03 -> Downstream Services
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:55
well, it can be but I wouldn't
CH4:D
@chad_d_stud_twitter
Aug 02 2018 08:56
what would be the issue?
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:57
it depends on your architecture
CH4:D
@chad_d_stud_twitter
Aug 02 2018 08:57
yes. i just want to understand why you wouldn't
Marcos Barbero
@marcosbarbero
Aug 02 2018 08:57
if I'm not mistaken there's a eureka-client for js (not really netflix official impl) where you can pick the zuul instances and rotate
but let's say for now you have only this FE and you added this complexity, tomorrow someone wants to start a mobile app, or even worst multiple FE clients for the same API
all of them will have to implement the same complexity
and then you got an external partner that needs to consume your APIs, are you going to expose all your eureka-clients to the partner?
doesn't sound like a good idea, does it?
CH4:D
@chad_d_stud_twitter
Aug 02 2018 09:02
well they only need to maintain the list of servers. the endpoints don’t change
Marcos Barbero
@marcosbarbero
Aug 02 2018 09:02
not really
Marcos Barbero
@marcosbarbero
Aug 02 2018 09:02
nope
CH4:D
@chad_d_stud_twitter
Aug 02 2018 09:02
at least that’s how i envision it
Marcos Barbero
@marcosbarbero
Aug 02 2018 09:03
I've a meeting now, I'll try to elaborate a little once I'm done with it
CH4:D
@chad_d_stud_twitter
Aug 02 2018 09:03
cool
Marcos Barbero
@marcosbarbero
Aug 02 2018 09:03
but in short think of Zuul as an edge service, so you treat it as such
I'll elaborate it later
CH4:D
@chad_d_stud_twitter
Aug 02 2018 09:03
so you’re saying zuul alone is safe for high traffic sites?
Marcos Barbero
@marcosbarbero
Aug 02 2018 09:04
nope
we gonna get there :smile:
CH4:D
@chad_d_stud_twitter
Aug 02 2018 09:04
alright :)
Marcos Barbero
@marcosbarbero
Aug 02 2018 09:04
meeting starting here
Marcos Barbero
@marcosbarbero
Aug 02 2018 10:04

so, let's walk through it @chad_d_stud_twitter
if you use a client-side load balancer for the FE you will add complexity to any other FE that you may need to implement.
It's not a matter of keeping a list of servers, you need a proper client-side load balancer if you want to have this scaleable as everything and all the consumers may need it, moreover, if you have an external consumer it sarts to be a problem where you are exposing your eureka-server and all it's clients to the external consumer.

Do you understand what I am saying?

CH4:D
@chad_d_stud_twitter
Aug 02 2018 10:05
yes
well it doesn’t have to be the FE
what about somethingl like nginx?
or one of those load balancers in aws?
Marcos Barbero
@marcosbarbero
Aug 02 2018 10:05
what for?
CH4:D
@chad_d_stud_twitter
Aug 02 2018 10:05
so Fe doesn’t have to directly implement it. they just access one server
and that server load balances through those gateways?
Marcos Barbero
@marcosbarbero
Aug 02 2018 10:06
that's where I wanted to get :)
CH4:D
@chad_d_stud_twitter
Aug 02 2018 10:06
or maybe a load balanced dns server?
Anyway the reason why i’m thinking of these solutions is because i’m trying to think of the scenario if the zuul gateway goes down.
Marcos Barbero
@marcosbarbero
Aug 02 2018 10:07
as I mentioned before, zuul should be in the edge and can add a load balancer tool on top of it, so the consumers will access something like http://yourdomain.com/api/** and it doesn't change
they don't need to keep client side load balancing logic or anything
CH4:D
@chad_d_stud_twitter
Aug 02 2018 10:08
yep. i get that part.
what do you mean by “edge”? as in edge server?
Marcos Barbero
@marcosbarbero
Aug 02 2018 10:09
just don't call zuul directly, you need a tool such as AWS ELB, nginx, bigIP, whatever you want to do the load balancing between the gateways
yeah, as in a edge server
CH4:D
@chad_d_stud_twitter
Aug 02 2018 10:09
Bingo. that’s what im talking about
we have those stuff here but it’s maintained by another team.
but at least now i know what to tell them we need
thanks :)
Marcos Barbero
@marcosbarbero
Aug 02 2018 10:10
that's fine, you all work in the same company and trying to achieve the same goal, just explain to them and get it working
not really a big deal :)
you're welcome
if you need more input, just drop a line
CH4:D
@chad_d_stud_twitter
Aug 02 2018 10:12
Sure. :thumbsup:
Thales Sousa
@tminussi
Aug 02 2018 18:06
@spencergibb do you know any work around this issue? I am facing the very same problem.
spring-cloud/spring-cloud-netflix#3021
Spencer Gibb
@spencergibb
Aug 02 2018 18:09
I don't
Thales Sousa
@tminussi
Aug 02 2018 18:09
My scenario is the same: I have 2 instances, then I kill one and boot it again. Zuul will start throwing 500 errors (GENERAL) because apparently it does not yet know that one of the instances is down. It takes roughly 2 mins to get everything back in place. I have tried many different configurations that I've found over the web and none of them seem to fix the issue. Is there a way to change the LB strategy when also using Eureka? All the solutions I found did not use Eureka, so they were explicitly declaring the list of servers for ribbon to look into.
Spencer Gibb
@spencergibb
Aug 02 2018 18:09
are you using retry?
that's not the same as described in 3021
Thales Sousa
@tminussi
Aug 02 2018 18:10
Is there any "default" configuration for Zuul you recommend that I could look up?
"When restart one node(17551) once node successfully come and when I send request via ZUUL , it immediately respond with 500 GENERAL ERROR."
That's my scenario, did I miss something on my explanation?
Again, I tried many different things, so some properties may not make sense anymore. But I tried hard before posting it here.
Thales Sousa
@tminussi
Aug 02 2018 18:50
Will give it a try! Thanks!
Thales Sousa
@tminussi
Aug 02 2018 19:44
no luck, @spencergibb. I will open an issue describing it accordingly.
Spencer Gibb
@spencergibb
Aug 02 2018 20:26
your going to have to describe how to get your app in the state it fails
why do all of the projects have eureka server?
Thales Sousa
@tminussi
Aug 02 2018 20:29
they should not. I will remove Eureka server from both Morannon and Station.
Marcos Barbero
@marcosbarbero
Aug 02 2018 20:59
@tminussi do you mind if I ask how are you starting those 2 instances? is it 2 instances of the same service, right?
Is it running in localhost or elsewhere?