Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Based on https://medium.com/must-know-computer-science/system-design-load-balancing-1c2e7675fc27

...

Load balancers are generally grouped into two categories: Layer 4 and Layer 7.

...

Layer 4 load balancers

  • It acts upon data found in network and transport layer protocols (IP, TCP, FTP, UDP). They are mostly the network address translators (NATs) which share the load to the different servers getting translated to by these load balancers.

  • Session persistence can be achieved at the IP address level

  • No termination for TCP connections

...

NAT Mode: The clients get connected to the service VIP. The load balancer chooses a server in the pool then forwards packets to it by changing the destination IP address (DNAT), the LB becomes the default gateway for the real servers, and the source IP is the client’s IP. All traffic will pass through the load balancer, and output bandwidth is limited by load balancer output capacity. There is only one connection established.

...

Tip

Example: Azure Load Balancer and not Azure Application Gateway, Nginx as TCP and UDP load balancer

Layer 7 load balancers

  • It distributes requests based upon data found in application layer protocols such as HTTP. They can further distribute requests based on application-specific data such as HTTP headers, cookies, or data within the application message itself, such as the value of a specific parameter.

  • For the client, the destination IP will be the IP of the load balancer, for the backend server, the source IP will be the IP of the load balancer.

  • The cookie can be used to achieve a sticky session.

  • IP of the client will be kept with the X-Forwarded-For header.

  • To get the HTTP information, the connection is terminated at the load balancer, thus, there will be 2 TCP connections: Client-LB, LB-Backend.

Tip

Example: Azure Application Gateway and not Azure Load Balancer, Nginx as HTTP load balancer

...

  • Between user and web servers (User => Web Servers)

  • Between web servers and an internal platform layer (application servers, cache servers) (Webservers => App or Cache servers)

  • Between internal platform layer and database (App or Cache servers => Database servers)

5. Algorithms

  • Least connection

  • Least response time

  • Least bandwidth

  • Round robin

  • Weighted round-robin

  • IP hash

...

Using this method, client requests are routed to available servers on a cyclical basis. Round robin server load balancing works best when servers have roughly identical computing capabilities and storage capacity.

...