What Is a Load Balancer and How Does It Work?
What is a load balancer and what does it do? Balancing methods, health checks, session handling, load balancing with Nginx, HAProxy and when you need one.

Contents
A load balancer is a system that distributes incoming requests across several servers. Visitors connect to a single address, and the load balancer forwards each request to one of the servers behind it. That way, traffic a single server couldn't handle is shared among several servers, and when one of them fails, the others keep serving.
This article covers how a load balancer works, load distribution methods, health checks, session handling, a simple load balancing setup with Nginx and when you need a load balancer.
What does a load balancer do?
- Scaling: When traffic grows, instead of moving to a bigger server (vertical scaling), you increase capacity by adding new servers (horizontal scaling).
- High availability: When a server goes down or is taken out for maintenance, the load balancer sends the traffic to the other servers; visitors don't notice any downtime.
- Updates without downtime: You can take servers out of service one at a time and update them.
- A single entry point: The SSL certificate, compression and security rules are managed in one place.
We explain how the availability of your service is measured in our What is uptime? article.
Load distribution methods
| Method | How does it work? | When? |
|---|---|---|
| Round robin | Sends requests to each server in turn | Servers are equally powerful, requests similar |
| Weighted round robin | Sends more requests to more powerful servers | Servers have different capacities |
| Least connections | Picks the server with the fewest active connections | Request durations vary widely |
| IP hash | Always sends the same IP address to the same server | Sessions need to stay on a single server |
Health checks
The load balancer regularly checks whether the servers behind it are working. If a server doesn't respond or returns errors, it stops sending requests to it; once the server recovers, it brings it back into service. That way, a single server going down doesn't show up as an error for visitors. Setting up a simple /health address in your application that also checks the database connection makes health checks more meaningful.
Sessions and shared data
When there are several servers behind the load balancer, a user's consecutive requests can go to different servers. That's why:
- Keep sessions in a shared place. If sessions sit in a single server's memory or on its disk, the user is logged out when they land on another server. Keeping sessions in a shared store such as Redis is the cleanest fix; the details are in our What is Redis? article.
- Share uploaded files. Files users upload should be kept on storage all servers can reach, or in object storage.
- There's usually a single database. While application servers are replicated, they all connect to the same database. Make the database reachable from the servers only over a private network.
If these aren't possible, you can always send the same user to the same server with IP hash or sticky sessions; however, this can lead to the load being distributed unevenly.
Load balancing with Nginx
As well as working as a reverse proxy, Nginx also works as a simple and powerful load balancer. The servers behind it are defined in an upstream block:
upstream app {
least_conn;
server 10.8.0.11:3000 max_fails=3 fail_timeout=30s;
server 10.8.0.12:3000 max_fails=3 fail_timeout=30s;
server 10.8.0.13:3000 backup;
}
server {
listen 443 ssl;
server_name yourdomain.com;
location / {
proxy_pass http://app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
least_conn: Sends requests to the server with the fewest active connections. If you remove the line, the default method is round robin.max_failsandfail_timeout: If a server fails repeatedly within the given time, it's taken out of service for a while.backup: A backup server used only while all the other servers are down.
We cover Nginx's basic configuration and SSL in our How to install Nginx guide. Instead of exposing the ports of the servers behind it to the internet, keep them on a private network only the load balancer can reach; you can use WireGuard to connect the servers to each other securely.
HAProxy and other options
- HAProxy: An open-source tool focused purely on load balancing and proxying, proven at very high traffic. It offers advanced health checks and detailed statistics, and it can also load balance at the TCP level.
- DNS round robin: Publishing several A records for the same domain is the simplest distribution method. However, DNS doesn't know when a server has gone down and can keep sending visitors to it; it isn't a substitute for a real load balancer.
- Cloud and provider load balancers: Some providers offer managed load balancer services; setup and redundancy are the provider's responsibility.
Making the load balancer itself redundant
A single load balancer is itself a single point of failure: if it goes down, the site can't be reached even if all the servers behind it are healthy. In critical systems, two load balancers run, and when one goes down, the other takes over the traffic. Before building this kind of setup, find out what network features your provider offers.
When do you need a load balancer?
Most projects don't need a load balancer. Try these first:
- Optimize the application and the database. Slow queries and missing caching are much cheaper to fix than adding servers; take a look at our Why is my server slow? article.
- Use caching and a CDN. Move static content to a CDN and repeated queries to Redis.
- Move to a more powerful server. Vertical scaling is much simpler than horizontal scaling.
A load balancer makes sense when:
- A single server's resources can't carry the traffic, even after optimization.
- The service must not go down while a server fails or is under maintenance.
- You want to release new versions of your application without downtime.
Nodesty servers for load balancing
Nodesty AMD Ryzen 9 9950X VPS plans can be used as application servers thanks to their high single-core speed, and AMD EPYC 7763 VPS plans as database and cache servers thanks to their generous RAM. The Frankfurt and New York locations of the 9950X plans let you run servers in different regions. All plans include NVMe storage, nShield DDoS protection and free daily backups kept for 7 days. On virtual servers, bandwidth usage and high-traffic reverse proxy applications are subject to our Fair Use Policy; for setups that will carry very high traffic, consider our dedicated servers, where the hardware is reserved entirely for you.
Frequently Asked Questions
Does a small site need a load balancer?
Usually not. Most sites and applications run comfortably on a single powerful server with caching and a CDN. A load balancer makes sense when a single server's resources aren't enough, or when the service must not go down if a server fails.
What's the difference between a load balancer and a reverse proxy?
A reverse proxy forwards requests to an application behind it; a load balancer does the same by distributing them across several servers. Tools such as Nginx and HAProxy can do both jobs; with a single backend they work as a reverse proxy, and with several backends as a load balancer.
How are sessions kept across servers?
If user sessions are kept in a single server's memory or on its disk, the session is lost when another server handles the request. To prevent this, you can keep sessions in a shared store such as Redis, or use sticky sessions, which always send the same user to the same server.
What happens if the load balancer itself goes down?
A single load balancer is itself a single point of failure. In critical systems, two load balancers run so that when one goes down, the other takes over its traffic. In simpler setups, publishing several addresses through DNS also provides partial redundancy.
Are load balancers used for game servers?
Because a game world usually runs in a single server process, classic load balancing isn't used much for game servers. Proxies in Minecraft networks (for example Velocity) distribute players across different backend servers and play a similar role.
Should I load balance the database too?
Replicating application servers is easy, but the database usually stays on a single primary server that all the application servers connect to. If the read load is very high, read replicas can be added; this is a more complex job than replicating application servers.
About the author
Nodesty Team · Infrastructure & Support
The Nodesty team runs our servers, network and DDoS protection day to day and answers customer support requests around the clock. These guides come from that work.
Related articles

How to Upgrade Ubuntu Server to the Next LTS Release
How to upgrade an Ubuntu server to the next LTS release: backups, preparation, do-release-upgrade, SSH access, post-upgrade checks and a clean install.

How to Deploy a Laravel App to a VPS
How to deploy Laravel to a server: PHP-FPM, Composer, .env, the database, file permissions, Nginx, queue workers, the scheduler, SSL and shipping updates.

How to Install PostgreSQL: Linux Server Guide
How to install PostgreSQL on a Linux server: creating roles and databases, access with pg_hba.conf, remote connections, pg_dump backups and tuning.