Kahibaro
Discord Login Register

5.5 Load Balancing

Why Load Balancing Matters

In server environments, load balancing lets you:

At a high level, a load balancer sits between clients and your backend servers:

$$
\text{Client} \rightarrow \text{Load Balancer} \rightarrow \text{Backend Servers}
$$

The rest of this chapter focuses on concepts and Linux-oriented implementation details that are common across different load balancer technologies (HAProxy, Nginx, etc.), without going into configuration specifics that belong in their dedicated chapters.

Load Balancing Architectures

Layer 4 vs Layer 7 Load Balancing

Load balancers typically operate at:

On Linux, both types are implemented using user-space software like HAProxy or Nginx, sometimes combined with kernel features like IPVS (IP Virtual Server) for high-performance L4 balancing.

Single vs Multi-Tier Load Balancing

You will often see more than one load balancer in a production architecture:

Example pattern:

Linux boxes can serve in any of these roles using the same core tools but with different configuration.

Traffic Distribution Algorithms

Algorithms define how a load balancer assigns new connections/requests to backends. Common strategies:

Round Robin

Weighted Round Robin

Example:

Over time, ratio of requests:

$$
A : B : C = 4 : 2 : 1
$$

Use this to accommodate different server sizes or temporarily reduce load on a weaker node.

Least Connections / Least Load

Variants:

These require more metrics from backends.

Source / Hash-Based

Random (With or Without Weights)

Health Checks and Failover

The usefulness of a load balancer depends heavily on detecting when backends are unhealthy and avoiding them.

Types of Health Checks

Health Check Behavior

Typical parameters you’ll tune:

Operational patterns:

Passive vs Active Checks

Usually you’ll combine both.

Session Persistence (Stickiness)

Stateful applications often need the same client to keep hitting the same backend (e.g., in-memory sessions, shopping carts without shared storage).

Common persistence methods:

IP-Based Persistence

Cookie-Based Persistence

Variations:

URL / Header-Based Persistence

Trade-Offs

SSL/TLS Termination and Offloading

Load balancers are often the first point where TLS is handled.

TLS Termination

Benefits:

Risks / considerations:

TLS Passthrough

Use when:

Trade-offs:

Re-Encryption

Pattern:

Used when you want both:

High Availability for Load Balancers

A single load balancer is itself a single point of failure. High-availability (HA) load balancing ensures the LB tier is redundant.

Active-Passive vs Active-Active

Techniques on Linux

Common components:

Config Synchronization

For consistent behavior:

Load Balancing and DNS

DNS is not itself a full load balancer, but it’s often used in conjunction:

Simple DNS Round Robin

Characteristics:

GeoDNS / Latency-Based DNS

Integration with Traditional Load Balancers

Typical patterns:

Key limits:

Load Balancing Special Cases

TCP and UDP Services

Not all services are HTTP:

Long-Lived Connections

WebSockets, gRPC streams, or streaming protocols:

Strategies:

Observability and Tuning

To operate load balancing in production, you need visibility and tuning capabilities.

Key Metrics

Useful metrics per backend and per frontend/listener:

Logs

LB logs can be very detailed:

Centralize and analyze these logs to:

Performance Considerations

On Linux:

Design Patterns and Practical Scenarios

Blue-Green and Canary Deployments

Load balancers are central in deployment strategies:

Multi-Tenancy

Graceful Maintenance

When you need to take a backend out:

This is often implemented directly in LB configuration or via an API/CLI.

Summary

Load balancing on Linux is a combination of:

The concrete implementations (HAProxy, Nginx, etc.) build on these concepts; mastering them conceptually makes it easier to read, design, and debug any specific configuration in later chapters.

Views: 117

Comments

Please login to add a comment.

Don't have an account? Register now!