Proxies

Load Balancers

Screenshot 2023-10-31 at 9.26.47 AM.png

Works as a type of reverse proxy, you redirect cleints requests / Traffic based on some logic the server admin has determined in the load balancer.

After you throw in a load balancer, you can then horizontally scale those servers as needed.

How exactly do we distribute that traffic evenly though?

Many Algorithms to do this! (Round Robbin, Weighted Round Robin, User Location, Least Number of COnnections, Layer 4 and Layer 7 Load Balancing)

Algorithms for Load Distribution

  1. Round Robbin → essentially just send a request sequentially to each server as they come, and keep going until. I.e. suppose you have 3 servers. Req1 → Server 1, Req2 → Server 2, Req3 → Server3, and then Req4 → Server 1, …, and so on.

    Screenshot 2023-10-31 at 10.00.00 AM.png

  2. Weighted Round Robbin → Each server gets requests based on how much they’ve been configured to handle (i.e in the diagram below, 50% of the requests should go to server 1, and 25% to server 2 & 3)

    Screenshot 2023-10-31 at 10.00.30 AM.png

  3. Least Number of Connections → Send requests to server that is currently dealing with the LEAST number of requests. ****

  4. User Location If users are geographically located closer to a specific server, we could route them to the server that is closest to them

    Under this strategy, we want to ensure that users receive data from the nearest server, minimizing the distance that data needs to travel. This approach helps reduce latency and provides a faster and smoother user experience.

    If our servers A, B, and C located in Asia, Europe, and North America, respectively, the load balancer uses the user's IP address to determine their location. Based on this information, the load balancer routes the user's request to the corresponding server that is geographically closest to them. This helps optimize response times and reduces latency by delivering the content from the server in close proximity to the user.

  5. Layer 4 and Layer 7 → Load balancers at different levels of network layers

What happens if you only have 1 load balancer? What if it goes down itself?

Consistent Hashing