Operations 14 min read

Mastering Load Balancing: Principles, Types, Algorithms, and Hardware Solutions

Load balancing distributes incoming traffic across multiple servers to enhance performance, ensure high availability, and enable horizontal scaling, with various implementations such as DNS, HTTP, IP, link‑layer, and hybrid methods, each employing algorithms like round‑robin, random, least connections, hash, and weighted distribution, plus hardware options.

21CTO
21CTO
21CTO
Mastering Load Balancing: Principles, Types, Algorithms, and Hardware Solutions

When facing massive user traffic, high concurrency, and large data volumes, high‑performance servers, large databases, and efficient programming languages (e.g., Go, Scala) are required; once a single machine reaches its limits, business splitting and distributed deployment become necessary to handle large‑scale website traffic.

Moving from a single‑machine site to a distributed one hinges on business splitting and deployment across multiple machines, forming a large‑scale distributed system. To address single‑point failures, redundant instances are deployed, and a load‑balancing device is placed before the cluster to distribute traffic.

Load balancing means distributing workload or request traffic across multiple operational units (servers or components) to achieve high performance, high availability, and horizontal scalability.

This article is the first part of a detailed load‑balancing series, covering principles, classifications (DNS, HTTP, IP, link‑layer, hybrid), and notes from reading material.

1. Load Balancing Principles

System expansion can be vertical (adding CPU, memory, disk to a single machine) or horizontal (adding more machines). Horizontal scaling is essential for large‑scale distributed systems that cannot be satisfied by vertical scaling alone.

Application Cluster: Deploy the same application on multiple machines to form a processing cluster that receives requests from the load‑balancing device.

Load‑Balancing Device: Distributes user requests to a server in the cluster based on a load‑balancing algorithm.

Load balancing solves the following problems:

Alleviates concurrency pressure and improves throughput.

Provides fault‑tolerance for high availability.

Offers scalability by adding or removing servers.

Enhances security through filtering, black‑/white‑listing, etc.

2. Load Balancing Types

2.1 DNS Load Balancing

The earliest technique uses DNS to resolve multiple A records, each pointing to a server in a cluster. Large sites often use DNS as the first level of load balancing.

Advantages

Simple to use: DNS handles the load‑balancing work, eliminating the need for a dedicated device.

Performance boost: DNS can resolve to the nearest server address, speeding up access.

Disadvantages

Poor availability: DNS changes propagate slowly, causing temporary failures.

Low scalability: Control resides with the domain registrar, limiting improvements.

Maintenance challenges: No real‑time server status, limited algorithms, cannot differentiate server health.

Practical Advice

Use DNS as the first level, mapping A records to internal load‑balancer IPs, which then distribute requests to real web servers. Suitable for internet companies; not ideal for complex business systems.

2.2 IP Load Balancing

Operates at the network layer by modifying the destination IP address.

When a request reaches the load‑balancer, it selects a real server based on an algorithm, rewrites the destination IP, and forwards the packet without involving user‑space processing.

After processing, the real server’s response returns to the load‑balancer, which rewrites the source IP to its own address before sending it back to the client.

Advantages

(1) Data distribution occurs in the kernel, offering better performance than application‑level solutions.

Disadvantages

(2) All traffic must pass through the load‑balancer, making its network‑card bandwidth a potential bottleneck.

2.3 Link‑Layer Load Balancing

Modifies MAC addresses at the data‑link layer to distribute traffic.

Servers share a virtual IP that matches the load‑balancer’s IP; the load‑balancer changes only the target MAC address, leaving IP addresses untouched, enabling direct routing (DR mode).

Advantages

High performance because packets bypass the load‑balancer’s IP processing.

Disadvantages

Complex configuration.

Practical Advice

DR mode is currently the most widely used link‑layer load‑balancing method.

2.4 Hybrid Load Balancing

Different server groups may use the most suitable load‑balancing method for each group, then another layer of load balancing aggregates these groups into a single service, achieving optimal performance. This approach is common in large internet companies and can also address scenarios where a single device cannot handle massive connections.

3. Load Balancing Algorithms

3.1 Round Robin

Distributes requests sequentially across servers, suitable when servers have identical hardware.

Pros : Even request distribution.

Cons : Not ideal for heterogeneous server capacities.

3.2 Random

Assigns requests to servers randomly.

Pros : Simple to implement.

Cons : Unsuitable for servers with differing capacities.

3.3 Least Connections

Routes requests to the server with the fewest active connections.

Pros : Dynamically balances based on current load.

Cons : More complex; requires monitoring connection counts.

3.4 Hash (Source‑Address Hash)

Hashes the client IP to select a server, ensuring that the same client is consistently directed to the same server (session stickiness).

Pros : Maintains session affinity.

Cons : If the chosen server fails, the session is lost.

3.5 Weighted

Extends other algorithms by assigning weights to servers, influencing the proportion of traffic each receives.

Pros : Allows fine‑tuned traffic distribution based on server capacity.

Cons : More complex to configure.

4. Hardware Load Balancing

Hardware load balancers are dedicated appliances (e.g., F5, A10) that provide high‑performance, high‑availability traffic distribution, often at a significant cost.

Considerations

Functionality: Support for multiple layers, diverse algorithms, and global load balancing.

Performance: Capable of handling far more concurrent connections than most software solutions.

Stability: Enterprise‑grade hardware undergoes rigorous testing and offers high reliability.

Security: Integrated firewall, DDoS protection, and other security features.

Maintenance: Management UI, support services, and technical assistance.

Cost: Premium pricing (e.g., F5 Big‑IP 150k‑550k RMB, A10 550k‑1M RMB).

Drawbacks

High price.

Limited scalability compared to software solutions.

4.4 Summary

Hardware load balancers typically require dual‑node high‑availability setups, increasing cost. Most internet companies prefer open‑source software load balancers (e.g., Nginx) and reserve hardware solutions for specific high‑performance needs.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Distributed SystemsScalabilityhigh availabilityload balancingHardwarenetwork algorithms
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.