Operations 12 min read

Master Load Balancing: Principles, Types, and Algorithms Explained

Load balancing distributes traffic across multiple servers to improve performance, ensure high availability, and enable scalability, covering concepts such as vertical and horizontal scaling, business partitioning, various load‑balancing methods (DNS, HTTP, IP, layer‑2, hybrid), and common algorithms like round‑robin, random, least connections, hash, and weighted distribution.

21CTO
21CTO
21CTO
Master Load Balancing: Principles, Types, and Algorithms Explained

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 needed; once a single machine reaches its limits, business partitioning and distributed deployment become essential to handle large‑scale website traffic.

1. Load Balancing Principles

System scalability can be vertical (adding CPU, memory, storage to a single machine) or horizontal (adding more machines). Horizontal scaling forms a cluster with a load‑balancing device that distributes requests among multiple servers, as shown in the diagram below.

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 according to a load‑balancing algorithm.

The purpose of load balancing is to solve high concurrency pressure, improve throughput, provide fault‑tolerance for high availability, enable horizontal scaling, and add security filtering (e.g., black‑white lists).

2. Load Balancing Classification

Based on implementation technology, load balancing can be divided into DNS, HTTP, IP, layer‑2, and hybrid types.

2.1 DNS Load Balancing

Uses multiple A records in DNS to map a domain to a set of servers, forming a cluster. It is simple and can improve performance by directing users to the nearest server, but suffers from poor availability, low scalability, and limited maintainability.

Practice: Use DNS as the first‑level load balancer, with A records pointing to internal load‑balancing IPs; suitable for internet companies with simple architectures.

2.2 IP Load Balancing

Operates at the network layer by modifying the destination IP address of packets. The load‑balancing server selects a real server IP based on an algorithm, rewrites the packet’s destination, and forwards it. Responses are sent back through the load balancer, which may perform source NAT.

Advantages: Kernel‑level processing offers better performance. Disadvantages: All traffic passes through the load balancer, making its network interface a potential bottleneck.

2.3 Layer‑2 Load Balancing

Modifies MAC addresses at the data‑link layer, keeping IP addresses unchanged. Servers share a virtual IP that matches the load balancer’s IP, allowing direct packet forwarding without address translation (Direct Routing mode).

Advantages: High performance. Disadvantages: Complex configuration.

2.4 Hybrid Load Balancing

Combines different load‑balancing methods across multiple server groups, then balances traffic among those groups, achieving optimal performance. It is widely used by large internet companies and can handle static‑dynamic separation scenarios.

Two example architectures are illustrated below.

3. Load Balancing Algorithms

Common algorithms include round‑robin, random, least connections, source‑address hash, and weighted distribution.

3.1 Round‑Robin

Requests are assigned to servers in order. Simple and ensures equal request count, but unsuitable when servers have different capacities.

3.2 Random

Requests are assigned randomly. Easy to implement, but also unsuitable for heterogeneous server resources.

3.3 Least Connections

Directs traffic to the server with the fewest active connections, providing dynamic load distribution based on current load; implementation is more complex due to monitoring requirements.

3.4 Hash (Source‑Address Hash)

Hashes the client IP to consistently route a client’s requests to the same server, enabling session stickiness; however, if the target server fails, the session is lost.

3.5 Weighted

Extends other algorithms by assigning weights to servers, allowing finer control over traffic distribution; adds configuration complexity.

4. Hardware Load Balancing

Dedicated hardware appliances (e.g., F5, A10) provide high‑performance, feature‑rich load balancing, including support for multiple layers, global algorithms, and built‑in security (firewall, DDoS protection). They are expensive and typically used by large enterprises.

Considerations include functionality, performance (can handle >50k concurrent connections), stability, security features, management interface, and cost.

Drawbacks: high price and limited scalability.

4.4 Summary

Hardware load balancers usually 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‑throughput scenarios.

Source: http://www.cnblogs.com/itfly8/p/5043435.html
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 Systemsload balancingnetwork 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.