microsoft / service-fabric

Service Fabric is a distributed systems platform for packaging, deploying, and managing stateless and stateful distributed applications and containers at large scale.
https://docs.microsoft.com/en-us/azure/service-fabric/
MIT License
3.03k stars 399 forks source link

How to use service which is hosted in local service fabric cluster? #189

Closed Kevin818 closed 6 years ago

Kevin818 commented 6 years ago

I have setup service fabric cluster with 3 windows servers. In this, I deployed one stateless service. Now I want to access this service, which is the best way to do this?

http://10.112.22.101:8081 http://10.112.22.102:8081 http://10.112.22.103:8081

Above are the 3 urls of stateless service. How should I use them so that even one machine is down, it still can be workable for clients to user them?

Any best practice on this? I have spent lots of time on searching in github, while found nothing. Many Thanks.

chaholl commented 6 years ago

There are a few options for this but essentially they boil down to the same thing: you'll need a load balancer and/or reverse proxy. If you're running this in Azure and budget isn't a concern then API gateway may be an option. Alternatively, for the reverse proxy side of things you could look at things like https://traefik.io/ or maybe even roll your own - https://github.com/spoorendonk/service-fabric-reverse-proxy. Service Fabric has a built in reverse proxy but it's not really designed to be a front end, it's more to support features like Azure API Gateway - might be worth a look though.

From the load-balancing side of things, it's just a case of pointing whatever you use to the reverse proxy endpoint. The reverse proxy will deal with failover and such like. For example, although you have three servers and three instances of your service, you may have a situation where a server is up but a service instance on that server is down - the reverse proxy will handle that by routing traffic to another instance.

rishirsinha commented 6 years ago

The reverse proxy solution on the cluster will have the same issue as the original problem. You connect to a machine on the cluster and then tell it from there where to go. Because you are connecting to a single entry point if that point is down it is going to be an issue. That is why Azure SF clusters are always created with a load balancer. However, it is non-trivial to run a load balancer on premises. The other option is to augment the DNS with a new domain name from your app and have it configured to round robin between these 3 endpoints.

chaholl commented 6 years ago

@rishirsinha Sorry, I should have been clearer - the reverse proxy runs on all front-end nodes in the cluster. The load balancer distributes the load between these nodes and the reverse proxy makes sure that the traffic is handled by a functional service behind the scenes. Basic load balancing won't give you any fault tolerance unless there's some monitoring functionality built in.

rishirsinha commented 6 years ago

@chaholl Agreed.

Also running a load balancer for a 3 node cluster does not make sense. If you have a load balancer for other reasons, then you can approach this problem through a load balancer. Else, I think DNS or even hosts file editing might be cheaper solutions.

Kevin818 commented 6 years ago

Sound like that round robin is a cheaper way for most of cases. As mentions above, I want to deploy my web application to 3 servers with service fabric cluster. So I assume domain provider can bind one domain name with these 3 server's ip . From developer side, there is nothing need to do on this. Is my understanding correct? In this way, it can achieve high availability and basic load balance. As if we use nginx, it also need multiple servers to make nginx server be available all the time.

rishirsinha commented 6 years ago

@Kevin818 For the specific deployment you have the understanding you have is correct.

Kevin818 commented 6 years ago

This is very helpfull. Thank you for your time.