Question

I'm writing a website that is going to start using a load balancer and I'm trying to wrap my head around it.

  1. Does IIS just do all the balancing for you?
  2. Do you have a separate web layer that sits on the distributed server that does some work before sending to the sub server, like auth or other work?

It seems like a lot of the articles I keep reading don't really give me a straight answer, or I'm just not understanding them correctly, I'd like to get my head around how true load balancing works from a techincal side, and if anyone has any code to share that would also be nice.

I understand caching is gonna be a problem but that's a different topic, session as well.

Was it helpful?

Solution

IIS do not have a load balancer by default but you can use at least two Microsoft technologies:

  • Application Request Routing that integrates with IIS, there you should ideally have a separate web layer to do routing work,
  • Network Load Balancing that is integrated with Microsoft Windows Server, there you can join existing servers into NLB cluster.

Both of those technologies do not require any code per se, it a matter of the infrastructure. But you must of course remember about load balanced environment during development. For example, to make a web sites truly balanced, they should be stateless. Otherwise you will have to provide so called stickiness between client and the server, so the same client will be connecting always to the same server.

To make service stateless, do not persist any state (Session, for example, in case of ASP.NET website) on the server but on external server shared between all servers in the farm. So it is common for example to use external ASP.NET Session server (StateServer or SQLServer modes) for all sites in the cluster.

EDIT:

Just to clarify a few things, a few words about both mentioned technologies:

  • NLB works on network level (as a networking driver in fact), so without any knowledge about applications used. You create so called clusters consisting of a few machines/servers and expose them as a single IP address. Then another machine can use this IP as any other IP, but connections will be routed to the one of the cluster's machines automatically. A cluster is configured on each server, there is no external, additional routing machine. Depending on the clusters settings, as we have already mentioned, a stickiness can be enabled or disabled (called here a Single or None Affinity). There is also a Load weight parameter, so you can set weighed load distribution, sending more connections to the fastest machine for example. But this parameter is static, it can't be dynamically based on network, CPU or any other usage. In fact NLB does not care if target application is even running, it just route network traffic to the selected machine. But it notices servers went offline, so there will be no routing there. The advantages of NLB is that it is quite lightweight and requires no additional machines.
  • ARR is much more sophisticated, it is built as a module on top of IIS and is designed to make the routing decisions at application level. Network load balancing is only one of its features as it is a more complete, routing solution. It has "rule-based routing, client and host name affinity, load balancing of HTTP server requests, and distributed disk caching" as Microsoft states. You create there Server Farms with many options like load balance algorithm, load distribution and client stickiness. You can define health tests and routing rules to forward request to other servers. Disadvantage of all of it is that there should be a dedicated machine where ARR is installed, so it takes more resources (and costs).
  • NLB & ARR - as using a single ARR machine can be the single point of failure, Microsoft states that it is worth consideration to create a NLB cluster of ARR machines.

OTHER TIPS

Does IIS just do all the balancing for you?

Yes,if you configure Application Request Routing:

ARR in IIS

Do you have a separate web layer that sits on the distributed server

Yes.

that does some work before sending to the sub server, like auth or other work?

No, ARR is pretty 'dumb':

IIS ARR doesn't provide any pre-authentication. If pre-auth is a requirement then you can look at Web Application Proxy (WAP) which is available in Windows Server 2012 R2.

It just acts as a transparent proxy that accepts and forwards requests, while adding some caching when configured.

For authentication you can look at Windows Server 2012's Web Application Proxy.

Some tips, and perhaps items to get yourself fully acquainted with:

  • ARR as all the above answers above state is a "proxy" that handles the traffic from your users to your servers.

  • You can handle State as Konrad points out, or you can have ARR do "sticky" sessions (ensure that a client always goes to "this server" - presumably the server that maintains state for that specific client). See the discussion/comments on that answer - it's great.

  • I haven't worn an IT/server hat for so long and frankly haven't touched clustering hands on (always "handled for me automagically" by some provider), so I did ask this question from our host, "what/how is replication among our cluster/farm" done?" - The question covers things like

    • I'm only working/setting things on 1 server, does that get replicated across X VMs in our cluster/farm? How long?
    • What about dynamically generated,code and/or user generated files (file system)? If it's on VM1's file system, and I have 10 load balanced VMs, and the client can hit any one of them at any time, then...?
    • What about encryption? e.g. if you use DPAPI to encrypt web.config stuff (e.g.db conn strings/sections), what is the impact of that (because it's based on machine key, and well, the obvious thing is now you have machine(s) or VM(s). RSA re-write....?
  • SSL: ARR can handle this for you as well, and that's great! But as with all power, comes a "con" - if you check/validate in your code, e.g. HttpRequest.IsSecureConnection, well, it'll always be false. Your servers/VMs don't have the cert, ARR does. The encrypted conn is between client and ARR. ARR to your servers/VMs isn't. As the link explains, if you prefer it the other way around (no offloading), you can...but that means all your servers/VMs should then have a cert (and how that pertains to "replication" above starts popping in your head).

Not meant to be comprehensive, just listing things out from memory...Hth

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top