TIC
The Interns Company
Fundamental

Load Balancing

ScalabilityHigh AvailabilityInfrastructure

Overview

Load balancing is the process of distributing incoming network traffic across multiple servers to ensure no single server bears too much demand. By spreading the load, load balancing improves application responsiveness and availability.

What is Load Balancing?

Load balancing is a critical component in most distributed systems and web architectures. It refers to the process of distributing network traffic across multiple servers to ensure that no single server bears too much load. This approach optimizes resource utilization, maximizes throughput, minimizes response time, and helps avoid server overload.

Load balancers can be implemented as hardware devices, software applications, or a combination of both. They sit between client devices and backend servers, receiving and then distributing incoming requests to any available server capable of fulfilling those requests.

Basic Load Balancer Architecture

Load Balancing Algorithms

Load balancers use various algorithms to determine which server should receive each client request. Some common algorithms include:

  • Round Robin: Requests are distributed sequentially across the server group.
  • Least Connections: New requests go to the server with the fewest active connections.
  • IP Hash: The client's IP address determines which server receives the request.
  • Weighted Round Robin: Servers with higher weights receive more connections.
  • Least Response Time: Directs traffic to the server with the lowest response time.
Common Load Balancing Algorithms

Layer 4 vs Layer 7 Load Balancing

Load balancers can operate at different layers of the OSI model:

  • Layer 4 (Transport Layer): Makes routing decisions based on IP address and TCP/UDP ports. Cannot see the actual content of the packet.
  • Layer 7 (Application Layer): Can make routing decisions based on the actual content of the message (HTTP headers, cookies, etc.)
Layer 4 vs Layer 7 Load Balancing

Load Balancer Health Checks

Load balancers perform regular health checks on the servers to ensure they are available and functioning correctly. If a server fails a health check, the load balancer stops sending traffic to it until it becomes healthy again.

Load Balancer Health Checks

Benefits of Load Balancing

  • Improved scalability: Handle increasing loads by adding more servers to the server pool
  • High availability: If one server fails, traffic is automatically redirected to other servers
  • Improved performance: Distribute workload efficiently across multiple servers
  • Flexibility: Add or remove servers without disrupting existing connections
  • Security: Can provide SSL termination and protect against DDoS attacks

Common Load Balancer Solutions

  • Hardware: F5 BIG-IP, Citrix ADC (formerly NetScaler)
  • Software: HAProxy, NGINX, Traefik
  • Cloud Services: AWS Elastic Load Balancing, Google Cloud Load Balancing, Azure Load Balancer
Cloud Load Balancing Architecture