Skip to main content

What Is Load Balancing and When Does a Website Actually Need It

In this article

Load balancing is the practice of putting one server in front of several identical copies of your application. That server hands each incoming request to whichever copy is healthy and least busy. The server in front is the load balancer. Visitors connect to it, never to the copies behind it, so a copy can fail, be replaced or be upgraded without anyone noticing.

Most business websites do not need one. A single well-sized server with sensible caching serves a few hundred thousand page views a month without strain. The things that actually make small sites fall over are a slow database query on a busy page or an unindexed table. Those are not fixed by adding a second copy of the same code.

You need a load balancer when one machine is measurably full after the cheap fixes. You also need one when the business cannot tolerate a single server being down for the hour it takes to rebuild. The third case is when you want to deploy new versions with no interruption on a site that is busy around the clock.

How a load balancer works

Where it sits

The load balancer owns the public address. DNS for your domain points at it, it holds the TLS certificate, and it keeps a list of backend servers with their private addresses. Each request arrives at the balancer, which opens a connection to one backend, forwards the request, and relays the response. A layer 4 balancer does this at the TCP level and never looks inside the traffic. A layer 7 balancer understands HTTP, so it can route by hostname or path, add headers, compress responses and terminate TLS. For a web application you almost always want layer 7.

Choosing a server

The simplest rule is round robin: first request to server A, second to B, third to C, then back to A. Least connections sends each request to whichever server is currently handling the fewest, which copes better when some requests are slow. IP hash sends the same visitor to the same server every time. It is a workaround for applications that keep state on the server and a sign that the application should be fixed instead.

Health checks

Every few seconds the balancer requests a known address on each backend, typically a /health/ endpoint that returns 200 only when the application can reach its database. A server that fails the check is taken out of rotation until it passes again. This is the feature that turns two servers into resilience rather than merely capacity. A crashed process, a full disk or a bad deploy on one machine means requests flow to the others instead of to an error page.

TLS termination

The balancer usually decrypts HTTPS and speaks plain HTTP to the backends over the private network, which centralises the certificate and spares each backend the handshake work. The application then has to be told it is behind a proxy, which in Django is the SECURE_PROXY_SSL_HEADER setting, so that it builds https links and marks cookies secure correctly.

What your application must give up

A load balancer only works if any copy of the application can handle any request. That means nothing may live only on one server's disk or in one process's memory. For a Django site the checklist is short and specific.

  • Sessions in the database or Redis, not in a local file or in-process cache. Django's default database sessions already pass.
  • Uploaded files in object storage such as S3-compatible buckets, not in a media folder on the server. A photo uploaded via server A must be visible to a page rendered by server B.
  • The cache in Redis or Memcached shared by all copies, not the per-process local memory cache, or each server will serve a different version of the same page.
  • Scheduled jobs and background workers running on one designated machine or a separate worker, so the nightly report is not sent three times.
  • Database migrations run once, before the new code starts, not by every server as it boots.
  • Logs shipped to one place, because an error that appeared on server C is otherwise invisible from server A.
  • Long-lived connections, such as WebSockets for live updates, need a layer 7 balancer that supports the protocol upgrade and long timeouts. WebSockets versus HTTP polling covers when they are worth it.

None of this is hard to build in from the start, and containers push you towards it by making local disk disposable. Retrofitting it onto a site that has written files to its own disk for three years is a project.

What a load balancer does not fix

A balancer moves the single point of failure; it does not remove it.

  • The database. Three application servers talking to one PostgreSQL instance are three ways to overwhelm it. The database needs its own plan: indexes and query tuning first, then a read replica or a managed service with automatic failover.
  • The balancer itself. A single Nginx box in front of two servers is one machine that can fail. Managed balancers from cloud providers are redundant internally, which is most of what you pay them for.
  • DNS and the certificate. An expired domain or certificate takes every server offline at once, balanced or not.
  • Slow code. If a page takes two seconds because of a query that scans a million rows, two servers deliver two-second pages to twice as many people. Profiling comes before provisioning.

A balancer is one part of a resilience plan, not the plan. The disaster recovery template is where to work out which failures actually threaten the business.

When a single well-sized server is the better answer

Scale is usually smaller than people fear. Our own UK Name Change service reached 6,141 Google clicks a month in September 2026. That sounds like a lot and is roughly two hundred visits a day: a load a single modest server serves without noticing. The traffic that strains a server is not visitors reading pages, it is uncached dynamic pages and expensive queries, and those are cheaper to fix than to spread.

The order of operations before a load balancer, each step typically worth more than the one after it:

  1. Cache what does not change per visitor. Full-page caching of the home page, category pages and blog posts means the server builds each once and serves it from memory thereafter. The layers of web caching explain where each kind belongs.
  2. Fix the slow queries. Django's debug toolbar on a staging copy shows which pages run hundreds of queries, and select_related and an index usually turn them into a handful.
  3. Serve static files and images from a CDN so the application server only answers for HTML.
  4. Resize the server. Doubling the memory and cores of a VPS is a reboot, and it is cheaper than a second server plus a balancer plus the engineering to make them share state.
  5. Reload gracefully. Zero-downtime deploys on one server are available for free: Gunicorn can start new workers on the new code and retire the old ones without dropping a request.

An online shop is the common case where people reach for a balancer early, because a sale day or a press mention feels like a capacity problem. In practice the product pages are cacheable, the checkout is a handful of requests per order handled by Stripe, and the server's job is small. The shops we build are designed so that a busy day is a caching question rather than an infrastructure one. That is also why the first fix for a slow shop is almost never a second server.

When you genuinely need one

  1. The single server is measurably full after the steps above. Sustained high processor use during normal hours, not a one-off spike, is the signal. This usually means a platform with many logged-in users doing uncacheable things, not a content site.
  2. The business cannot absorb an hour of downtime. If a lost hour costs more than the ongoing price of a second server and a managed balancer, redundancy pays for itself. The database then needs the same treatment or the hour has only moved.
  3. Deployments must be invisible on a site busy around the clock. Rolling one server at a time behind a balancer is the cleanest way to achieve it.
  4. Different workloads need different machines. A layer 7 balancer can route /api/ to one pool and the public site to another. That way a burst of API traffic from an integration partner does not slow the shop.

The options

On your own infrastructure, Nginx, HAProxy, Caddy and Traefik all balance well; a minimal Nginx configuration follows.

upstream app {
    least_conn;
    server 10.0.0.11:8000 max_fails=3 fail_timeout=30s;
    server 10.0.0.12:8000 max_fails=3 fail_timeout=30s;
}
server {
    listen 443 ssl;
    location / {
        proxy_pass http://app;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto https;
    }
}

Every cloud provider sells a managed balancer with built-in redundancy and certificate handling, the sensible choice once you are paying for two servers anyway. Managed platforms do it automatically when you set the instance count above one, provided the application already passes the statelessness checklist. Putting Cloudflare's free proxy in front of a site is caching and protection, not load balancing; their balancing product is a separate paid feature.

Questions people ask

Does a small business website need a load balancer?

Almost never. A single server with page caching, tuned queries and a CDN for images handles far more traffic than most small businesses will see. A balancer becomes relevant for platforms with many logged-in users or businesses that cannot tolerate an hour offline.

What is the difference between a load balancer and a reverse proxy?

A reverse proxy sits in front of one backend and handles TLS, caching and compression. A load balancer is a reverse proxy with more than one backend and the logic to choose between them and drop unhealthy ones. Nginx is both, depending on configuration.

Does a load balancer make my website faster?

Not on its own. Each request is still served by one application server at the same speed. It raises how many requests can be served at once, and it can offload TLS and compression, but a slow page stays slow. Caching and query fixes are what make pages faster.

How we handle this on our own builds

Most of the sites we build run on one well-sized server, with the database and uploaded files on that server's own disk, because that is all their traffic needs. Moving one behind a balancer would first mean moving the database to a managed service and the uploads to object storage, and we would do that when the numbers say so, not before. A second machine is a cost every month and a balancer is one more thing to monitor. If you are being sold a load balancer for a site with a few thousand visits a day, ask first what the slowest page does and whether it is cached.