Operations 16 min read

Mastering Load Balancing: From Basics to Advanced Algorithms

Load balancing distributes traffic across multiple servers to improve performance, reliability, and scalability, covering concepts from basic two- and three-layer methods to advanced four- and seven-layer techniques, and reviewing popular tools such as LVS, Nginx, and HAProxy along with various scheduling algorithms.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Mastering Load Balancing: From Basics to Advanced Algorithms

In the early stages of a website, a single machine provides centralized services, but as traffic grows, performance and stability become challenges, leading to the need for scaling via clusters and load balancing to distribute user requests across multiple servers.

Load Balancing Classification

Load balancing can be implemented at different OSI layers:

Layer 2 : Uses a virtual IP (VIP) and forwards packets by rewriting the destination MAC address.

Layer 3 : Uses a VIP but each server has a unique IP; forwarding is based on IP routing.

Layer 4 : Operates at the transport layer (TCP/UDP), modifying IP and port information to direct traffic to application servers.

Layer 7 : Operates at the application layer, using protocols such as HTTP, DNS, etc., to make routing decisions based on URL, browser type, language, and other request attributes.

Common Load Balancing Tools

Hardware load balancers offer high performance but are expensive; most internet services rely on software load balancers such as LVS, Nginx, and HAProxy.

LVS (Linux Virtual Server)

LVS provides high‑performance, high‑availability server clusters using a three‑layer architecture: a front‑end Load Balancer layer (Director), a Server Array layer of real servers, and a Shared Storage layer for data consistency.

Nginx

Nginx (Engine X) is a web server that also functions as a reverse proxy, HTTP/HTTPS load balancer, and cache. It uses a master‑worker process model: the master (running as root) loads configuration and spawns worker processes that handle client requests. Its modular design allows hot deployment and extensive feature extensions.

HAProxy

HAProxy is an open‑source, high‑availability load balancer and proxy for TCP and HTTP traffic. It is widely used for large‑scale web sites due to its reliability, rich feature set, and ability to protect backend servers.

Load Balancing Algorithms

Algorithms are divided into static and dynamic categories.

Round Robin : Cycles through servers sequentially; can assign weights for performance differences.

Random : Distributes requests randomly; simple but unsuitable for write‑heavy workloads.

Hash : Maps a key to a specific server, ensuring the same key always reaches the same node; useful for caches with read/write.

Consistent Hash : Minimizes key redistribution when a node fails, often combined with keepalived for high availability.

Least Connections : Sends traffic to the server with the fewest active connections.

Fastest : Directs requests to the server with the lowest response time.

Observed : Balances based on a combination of connection count and response time.

Predictive : Uses performance metrics to forecast the best server for the next time slice.

Dynamic Ratio, Dynamic Server Add, QoS, ToS, Rule‑Based : Advanced dynamic methods that adjust traffic based on real‑time resource usage, priorities, or custom policies.

Choosing the right algorithm depends on the application scenario, such as read‑only database load, cache with read/write, or real‑time services.

Source: https://www.cnblogs.com/kingreatwill/p/7991151.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.

load balancingLVSServer Clusteringbalancing algorithms
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.