Load Balancer #

When one server is no longer enough to handle incoming traffic, the solution is running several application instances and distributing requests among them. Nginx handles this well through the upstream block, which defines a group of backend servers along with their distribution rules.

This section covers all the load balancing algorithms available in Nginx, how to configure servers with different weights, session persistence, and health checks to make sure traffic isn’t directed to a down server.

Learning Map #

flowchart TD
    A["⚖️ Round Robin\nDefault — requests rotated\nin sequence"] --> B["📊 Least Connections\nRequests to the server\nwith the fewest connections"]
    B --> C["🔒 IP Hash\nSession persistence —\nthe same IP to the same server"]
    C --> D["🏋️ Weighted\nTraffic proportion controlled\nbased on server capacity"]
    D --> E["🩺 Health Check\nPassive failure detection\nand automatic failover"]

Articles in This Section #

ArticleAlgorithmWhen to Use
Round RobinEven rotationEqual-capacity servers, similar requests
Least ConnectionsPick the least busy serverRequests with varying durations
IP HashHash of the client IPSession persistence on local servers
WeightedProportion based on weightServers with different capacities, canary deploys
Health CheckPassive failure detectionEvery production setup
About | Author | Content Scope | Editorial Policy | Privacy Policy | Disclaimer | Contact