← All Concepts
Networking

Load Balancing

Distributes incoming traffic across multiple servers to ensure no single server is overwhelmed.

**Load balancers** sit between clients and servers, distributing requests to maintain optimal resource utilization and availability. **Types:** - **L4 (Transport layer)**: Routes based on IP and port. Fast, no payload inspection. - **L7 (Application layer)**: Routes based on HTTP headers, URL path, cookies. Smarter but slower. **Algorithms:** - **Round Robin**: Equal distribution, simple. - **Weighted Round Robin**: Higher capacity servers get more traffic. - **Least Connections**: Route to server with fewest active connections. - **IP Hash**: Same client always goes to same server (session affinity). - **Consistent Hashing**: Minimizes redistribution when servers change. **Health checks**: Active (periodic ping) and passive (monitor response errors). **Common tools**: AWS ALB/NLB, Nginx, HAProxy, Envoy.

Common Use Cases

  • Distributing web traffic across multiple app servers
  • Database read replicas load distribution
  • Microservice-to-microservice communication
  • Global traffic routing across data centers

Advantages

  • +Improves availability and reliability
  • +Enables horizontal scaling
  • +Can handle SSL termination
  • +Health checks remove unhealthy servers automatically

Disadvantages

  • -Adds latency (extra network hop)
  • -Can become a bottleneck or single point of failure
  • -Session stickiness complicates stateless design
  • -Configuration complexity increases with scale

Related Concepts

reverse proxyhorizontal scalinghealth checks