Skip to content

Latest commit

 

History

History
145 lines (102 loc) · 4.94 KB

File metadata and controls

145 lines (102 loc) · 4.94 KB

Load Balancer

What is a load balancer?

Wikipedia: "In computing, load balancing refers to the process of distributing a set of tasks over a set of resources (computing units), with the aim of making their overall processing more efficient."

Load balancer is a very important component in system design. You might already seen it mentioned in other sections like "horizontal scaling", so you understand that it's a very common component in many system designs.

There a couple of things to remember about load balancers:

  • Usually the IP address of the load balancer itself is public while the addresses of the instances/servers are private (there is no reason to allow users/clients to reach them directly and bypass the load balancer)
  • There are multiple techniques/algorithms as to how to perform the load balancing itself

Consistent Hashing

TODO

Load Balancing Techniques

Round Robin

Weighted Round Robin

Least Connection

Weighted Least Connection

Resource Based

Fixed Weighting

Weighted Response Time

Source IP Hash

URL Hash

Sticky Sessions

TODO

Health Checks

TODO

Questions

Why do we need load balancers?
What load balancing techniques are there?
  • Round Robin
  • Weighted Round Robin
  • Least Connection
  • Weighted Least Connection
  • Resource Based
  • Fixed Weighting
  • Weighted Response Time
  • Source IP Hash
  • URL Hash
True or False? Usually, in basic architectures, the servers behind a load balancer are using private IPs while the load balancer itself is using a public IP

True. This serves two purposes:

  • We want everyone to use the load balancer :)
  • It provides a better security, by not allowing everyone to reach the servers directly. This way, we can secure better one component rather taking care of the security of all the instances/servers behind the load balancer
Do you necessarily need a dedicated load balancer instance to perform load balancing? (using the round robin technique for example)

No, you can use a DNS server.

What is an application load balancer?
At what layers a load balancer can operate?
What is DNS load balancing?
What are the drawbacks of round robin algorithm in load balancing?
  • A simple round robin algorithm knows nothing about the load and the spec of each server it forwards the requests to. It is possible, that multiple heavy workloads requests will get to the same server while other servers will got only lightweight requests which will result in one server doing most of the work, maybe even crashing at some point because it unable to handle all the heavy workloads requests by its own.
  • Each request from the client creates a whole new session. This might be a problem for certain scenarios where you would like to perform multiple operations where the server has to know about the result of operation so basically, being sort of aware of the history it has with the client. In round robin, first request might hit server X, while second request might hit server Y and ask to continue processing the data that was processed on server X already.
What are sticky sessions? What are their pros and cons?
Explain each of the following load balancing techniques
  • Round Robin
  • Weighted Round Robin
  • Least Connection
  • Weighted Least Connection
  • Resource Based
  • Fixed Weighting
  • Weighted Response Time
  • Source IP Hash
  • URL Hash

Which load balancing technique would you use for e-commerce website? Why?

One that supports sticky sessions so users returning to the website, would have their data loaded, in case the server don't use shared storage.