Load balancing is spreading incoming traffic across several servers so no single server is overloaded.

Load balancing means putting a traffic director in front of a group of servers. Every request from a visitor reaches the load balancer first, and it decides which server should handle it. If you run an online shop on three identical web servers, the load balancer might send the first visitor to server one, the second to server two and the third to server three, so each machine does a third of the work.

The point is twofold: more capacity and fewer outages. When one server fails or is taken down for maintenance, the load balancer stops sending it traffic and the site stays up on the others.

How load balancing works

A load balancer can be dedicated hardware, software such as HAProxy or Nginx, or a managed service from a cloud provider or CDN. It picks a server for each request using a rule, for example:

  • Round robin: each server takes a turn in order.
  • Least connections: the server currently doing the least work gets the next request.
  • IP hash: a visitor's IP address always maps to the same server, which helps keep sessions together.
  • Weighted: bigger servers get a larger share of traffic.

The load balancer also runs health checks. It regularly asks each server for a test page, and if a server stops answering it is removed from the pool until it recovers.

Why load balancing matters for your website

A single server has a ceiling. Once you hit its CPU, memory or connection limits, pages slow down and eventually fail. Load balancing lets you add capacity by adding servers rather than replacing one machine with a bigger one. It also removes a single point of failure, which matters for sites where downtime costs real money.

For most small and medium websites, though, a fast single server with good caching handles far more traffic than people expect. Load balancing tends to come in once a site serves very high traffic or needs near-constant uptime.

Common load balancing problems

Spreading a site across servers creates new questions:

  • Shared files: uploads saved on one server must be visible on the others, usually through shared storage or object storage.
  • Sessions: if a logged-in visitor lands on a different server, they may be logged out unless sessions are stored centrally, often in Redis.
  • Databases: several web servers usually still talk to one database, which can become the next bottleneck.
  • SSL: certificates have to be installed on the load balancer or on every server.

Load balancing vs a CDN

A CDN caches copies of your pages and files at locations around the world and serves them close to the visitor. A load balancer shares live requests between your own origin servers. Many large sites use both: the CDN absorbs most traffic, and the load balancer spreads what's left across the origin.

Load balancing questions

Do I need load balancing for a small website?
Usually not. A single server with caching and a CDN comfortably handles most small and medium sites, and load balancing adds cost and complexity you won't need until traffic outgrows one machine.
Is a load balancer the same as a CDN?
No. A CDN serves cached copies of your content from locations near visitors, while a load balancer shares live requests between your own servers.
What happens if a server behind a load balancer goes down?
The load balancer notices through its health checks and stops sending traffic to that server. Visitors are served by the remaining servers, so the site stays online.
Was this definition helpful?
Share this definition