Load balancing is the mechanism for distributing incoming traffic across multiple servers. When load exceeds one server, split it across 2, 3, 10, or hundreds of servers. This raises uptime (if one server fails, others keep working) and improves performance (each server handles less load).
Types of load balancing
Round Robin โ each new request goes to the next server. The simplest and most widespread approach.
Least Connections โ send the request to the server with the fewest active connections. More accurate, slightly more complex.
IP Hash โ choose a server based on the user's IP address. A user always lands on the same server (for session continuity).
Weighted โ assign weights per server (more powerful servers get more traffic).
Geographic โ pick the server nearest to the user's location.
Types of load balancers
Software load balancer โ Nginx, HAProxy, Apache mod_proxy. Free, needs a server, but flexible.
Hardware load balancer โ F5, Citrix NetScaler. Expensive but high performance.
Cloud load balancer โ AWS ELB (Elastic Load Balancer), Google Cloud Load Balancing, Azure Load Balancer. Managed, pay-as-you-go, easy to set up.
Nginx load balancing example
The simplest configuration:
upstream backend {
server backend1.kompaniyam.uz weight=5;
server backend2.kompaniyam.uz weight=3;
server backend3.kompaniyam.uz weight=2;
}
server {
listen 80;
location / {
proxy_pass http://backend;
}
}
In this configuration backend1 gets 5/10 of traffic, backend2 3/10, backend3 2/10.
Session persistence
User sessions are stored on one server. If each request goes to a different server, the user gets logged out. Solutions: (1) IP Hash โ one user always lands on one server. (2) Sticky session โ the load balancer "pins" a user to a specific server. (3) Centralized session storage โ sessions live in Redis or a database, accessible from any server.
Health check
The load balancer health-checks each server every 5-30 seconds (HTTP request to a /health endpoint). If a server fails, traffic is automatically routed to the other servers. This is foundational for high availability.
Sayt.uz practice
2% of Sayt.uz clients use load balancing โ mostly large e-commerce and SaaS startups. Sayt.uz infrastructure itself uses load balancing (4 application servers with HAProxy). For clients we offer load-balancer setups on VPS Pro or Dedicated tariffs (custom configuration). Tip: load balancing is unnecessary overhead for small sites. It becomes worthwhile once you have 10,000+ daily active users.