Operations 6 min read

Designing a Million‑Level Load Balancing Architecture with LVS, Nginx, and Keepalived

This article explains how to build a high‑availability, million‑level concurrent architecture by combining Linux Virtual Server (LVS) for layer‑4 load balancing, Nginx for layer‑7 reverse proxy and caching, and Keepalived for VIP failover, including configuration examples and deployment modes.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Designing a Million‑Level Load Balancing Architecture with LVS, Nginx, and Keepalived

With the rapid growth of internet and mobile applications, single‑machine architectures can no longer handle million‑level concurrent traffic, so modern systems need high availability, load balancing, and elastic scaling.

The article proposes a combined architecture of Linux Virtual Server (LVS) for layer‑4 load balancing, Nginx for layer‑7 reverse proxy and caching, and Keepalived for virtual IP (VIP) failover, forming a four‑layer to seven‑layer traffic distribution pipeline.

In this design, LVS distributes incoming requests to Nginx instances, Nginx forwards them to backend application servers (e.g., Tomcat or Spring Boot), and Keepalived monitors LVS and Nginx to ensure the VIP migrates automatically when the master node fails.

The Nginx upstream block defines a pool of backend servers and can use algorithms such as least connections or IP hash. Example configuration:

upstream backend_servers {
    # load‑balancing algorithm
    # least_conn;
    # ip_hash;
    server
:
weight=5;
    server
:
weight=5;
    # ... add more application servers
}

Typical Nginx server configuration includes listening on a port, setting the server name, and proxying requests to the upstream pool while preserving headers:

server {
    listen
;
    server_name
;
    location / {
        proxy_pass http://backend_servers;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # other proxy settings
    }
}

LVS operates at the kernel level and supports several scheduling algorithms (Round Robin, Least Connections, Weighted Round Robin) and deployment modes (NAT, Direct Routing, IP Tunnel). It forwards client requests to real servers and can work together with Nginx to provide both layer‑4 and layer‑7 load balancing.

Keepalived uses the VRRP protocol to provide high‑availability for the virtual IP. A minimal Keepalived configuration is shown below:

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    virtual_ipaddress {
        192.168.1.100
    }
}

The complete architecture diagram illustrates the flow: client → VIP → LVS → Nginx (frontend) → application servers, with Keepalived ensuring failover for both LVS and Nginx layers.

By integrating LVS, Nginx, and Keepalived, the system achieves million‑level concurrent handling, balanced traffic distribution, and high availability.

Backend ArchitectureHigh Availabilityload balancingnginxLVSKeepalived
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

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.