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 #
| Article | Algorithm | When to Use |
|---|---|---|
| Round Robin | Even rotation | Equal-capacity servers, similar requests |
| Least Connections | Pick the least busy server | Requests with varying durations |
| IP Hash | Hash of the client IP | Session persistence on local servers |
| Weighted | Proportion based on weight | Servers with different capacities, canary deploys |
| Health Check | Passive failure detection | Every production setup |