Operations 20 min read

Overview of Software Load Balancing: Nginx, LVS, and HAProxy

This article provides a comprehensive overview of software load balancing, detailing the architecture, features, performance characteristics, and common deployment scenarios of Nginx, Linux Virtual Server (LVS), and HAProxy, and compares their load‑balancing strategies for high‑availability systems.

Architects' Tech Alliance
Architects' Tech Alliance
Architects' Tech Alliance
Overview of Software Load Balancing: Nginx, LVS, and HAProxy

Software load balancing is widely used in the Internet era as a cost‑effective alternative to expensive hardware load balancers; popular solutions include Nginx, LVS, and HAProxy.

1. Nginx Load Balancing

Nginx is a lightweight web server and reverse‑proxy that operates at the HTTP layer, supporting up to 50,000 concurrent connections using epoll/kqueue, written in C, and runs on Linux, Windows, and other OSes.

Features: modular design, high reliability, low memory usage (2.5 MB for 10 k keep‑alive connections), hot deployment, rich load‑balancing strategies, and extensive reverse‑proxy capabilities.

Core functions: static file serving, protocol reverse proxy (HTTP, SMTP, POP3), FastCGI, module filtering, SSL, health checks, virtual hosts, custom logging, graceful upgrades, keep‑alive, URL rewrite, access control, rate limiting, and connection limits.

Performance: official benchmark of 50 k concurrent connections; real‑world deployments often achieve 20‑30 k, with memory usage of ~2.5 MB for 10 k idle connections.

Architecture

A master process (running as root) spawns worker processes that handle request processing; modules are executed in a pipeline where each module performs a specific task such as header parsing, data lookup, or compression.

Hot deployment is achieved by the master reloading configuration without stopping workers; updated workers replace old ones after completing existing requests.

Sendfile Mechanism

Sendfile allows the kernel to transfer file data directly to the network socket, bypassing user‑space copying, which significantly reduces CPU usage and improves throughput for high‑concurrency workloads.

Load‑Balancing Strategies

Nginx provides built‑in strategies such as weighted round‑robin and IP‑hash, as well as extensible modules like fair, generic hash, and consistent hash. The article illustrates the weighted round‑robin algorithm and its depth‑first allocation behavior.

2. LVS Load Balancing

LVS (Linux Virtual Server) is an open‑source IP‑layer load balancer written in C, supporting NAT, TUN, and Direct Routing (DR) forwarding modes.

It operates at the network layer, distributing TCP/UDP requests among a pool of real servers, and can run on Linux or FreeBSD.

Functions and Architectures

NAT mode rewrites destination IPs at the director and source IPs on the return path.

TUN mode uses IP tunneling to forward packets directly to real servers, which reply to clients without passing through the director.

DR mode forwards packets to real servers on the same LAN segment, requiring MAC address rewriting.

The LVS architecture consists of a front‑end load‑balancer layer, a server array layer, and a shared storage layer.

Scheduling Algorithms

Round Robin

Weighted Round Robin

Least Connections

Weighted Least Connections

Locality‑Based Least Connections (with and without replication)

Destination Hashing

Source Hashing

Custom algorithms can also be implemented.

3. HAProxy Load Balancing

HAProxy is a high‑performance, open‑source load balancer that supports TCP (layer‑4) and HTTP (layer‑7) proxying, virtual hosts, and health checks.

It is known for handling higher concurrency than Nginx in certain scenarios and is often used for MySQL read‑replica balancing and session persistence.

Features

TCP and HTTP modes with virtual host support.

Simple configuration and URL‑based health checks.

Higher throughput under heavy load compared to Nginx.

Balancing Algorithms

roundrobin

static‑rr (based on server capacity)

leastconn

source (IP‑hash‑like)

Conclusion

The article summarizes the key concepts, architectures, and strategies of software load balancing using Nginx, LVS, and HAProxy, providing a practical reference for designing high‑availability and high‑concurrency systems.

backendoperationsLoad BalancingnginxHAProxylvs
Architects' Tech Alliance
Written by

Architects' Tech Alliance

Sharing project experiences, insights into cutting-edge architectures, focusing on cloud computing, microservices, big data, hyper-convergence, storage, data protection, artificial intelligence, industry practices and solutions.

0 followers
Reader feedback

How this landed with the community

login 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.