a system design guide

Load balancing explained: from one server to many

By Majid Ali, founder of Bytecrest · 8-minute read

Short answer

A load balancer gives users one address and spreads their requests across several servers. Round robin hands out turns equally. Least connections sends each request to the server with the fewest in flight, so it copes with uneven servers. Health checks remove dead servers. Work out capacity first: vCPUs ÷ CPU time per request.

Once one server is not enough, you add more. Then a new question appears: who decides which server gets each request? This guide covers the capacity maths that tells you when to add servers, the algorithms a balancer uses, and what happens when a server dies. The numbers come from the free load balancer Lessons in ByteLab, a system design simulator.

Why do you need more than one server?

Each request needs some CPU time. Say it costs about 10 ms of one vCPU, and the server has 2 vCPUs.

  • Capacity = vCPUs ÷ CPU time per request = 2 ÷ 0.010 s = 200 requests per second.
  • At 100 requests a second, that server is 50% busy. Comfortable.
  • A sensible planning limit is about 70% of capacity, which is 140 requests a second.
  • If a newsletter sends 240 a second, you ask for 240 × 10 ms = 2,400 ms of CPU every second. The server has 2,000. That is 120%.

The extra requests join a queue, and every new request waits behind it. You can scale up (a bigger server with 4 vCPUs, about 400 requests a second) or scale out (two identical 2-vCPU servers, also about 400). At 240 requests a second, 400 of capacity is 60% utilisation: calm. Scaling out has one catch. Something has to spread the requests. That is the load balancer.

What does a load balancer do?

A load balancer is a machine that runs no application code. It accepts each request, picks a backend server, forwards the request and passes the response back. The users only ever know one address. You can add or remove servers behind it without anyone noticing.

Which load balancing algorithms are there?

Four classic ones, from simplest to smartest:

Load balancing algorithms compared
AlgorithmHow it choosesTrade-off
Round robinTakes the servers in turn: 1, 2, 1, 2.No state needed. Assumes every server and every request is the same.
Least connectionsSends each request to the server with the fewest requests in flight right now.Adapts to uneven servers with no setup. Counts requests, not how heavy they are.
Weighted round robinGives each server a share in proportion to a weight you set, such as 1 : 4.Works while the weights stay true. You must update them by hand.
IP hashHashes the client address, so the same client always reaches the same server.Cheap stickiness. A few heavy clients can pin one server.

What goes wrong with round robin?

Real pools are rarely uniform. You buy what is cheap that month, grow in steps and inherit old hardware. Take a pool of one small server (2 vCPUs) and one big one (8 vCPUs), with 10 ms of CPU per request.

  • Small server capacity: 2 ÷ 0.010 = 200 requests per second.
  • Big server capacity: 8 ÷ 0.010 = 800 requests per second.
  • Pool capacity: 1,000. Users send 500, so the pool is only 50% busy. On paper, it is fine.

Round robin splits requests 1 : 1, so each server is offered 250 a second. The big one is 31% busy. The small one is offered 250 ÷ 200 = 125%. A queue forms and keeps growing. The pool has twice the capacity it needs and is still in trouble, because round robin ignores capacity.

Switch to least connections and nothing else changes. The big server finishes work four times faster, so it has fewer requests in flight four times as often, and it gets more. The split settles at about 100 a second to the small server and 400 to the big one: both near 50%. Nobody told the balancer those numbers. It found them.

Weighted round robin also fixes this, with weights of 1 : 4. But the weights go stale when someone resizes a machine. Least connections counts requests, not their cost, so a mix of 2-second reports and 5 ms lookups still tilts the load.

What is the difference between L4 and L7?

The layer decides what the balancer can see. L4 works on TCP connections. It looks at addresses and ports, picks a backend for the connection and moves bytes. It cannot read HTTP, which makes it fast and cheap, and it suits any protocol.

L7 reads the HTTP request. It can route by path (/api to one pool, /images to another), terminate TLS, retry a failed request on another server and run real health checks. That costs more CPU per request. A common shape is an L4 balancer at the edge and L7 balancers behind it. For a few hundred requests a second, L7 is the sensible default.

How do health checks work?

The balancer does not know a server is dead until its next health check. It pings each backend on a fixed interval. With a 2,000 ms interval, some requests still go to a dead server for up to 2 seconds. At 500 requests a second, about 1,000 requests arrive in that window, and with round robin up to half go to the dead server and fail. At a 500 ms interval the window holds about 250.

Shorter is not free. Every check costs traffic and CPU on every backend. A check that is too nervous mistakes a slow answer for a dead server and removes a healthy one, which shifts its load onto the others.

Can the survivors carry the load?

When a server dies, the others take its share. In the pool above, if the small server crashes, the big one carries all 500 requests a second against 800 of capacity. Fine. If the big one crashed instead, the small server (200) could not cope. Failover only works if the survivors are sized for it. A pool that is fine at full strength can collapse when it loses its biggest member.

And look at the balancer itself. If every request goes through one machine and it crashes, nothing reaches any backend. Run a pair that share one address, or use a managed balancer that spans zones.

Common mistakes

  • Using round robin on a mixed pool. It assumes every server is the same.
  • Sizing from the average. Size for the peak, and aim for about 70% utilisation, not 100%.
  • Forgetting failover capacity. Ask what the pool can carry with its biggest server gone.
  • Running one balancer. You moved the single point of failure in front of the servers.
  • Setting the health check interval without doing the sum. Interval × request rate is how many requests fail before a crash is noticed.
  • Using IP hash with few clients. A single busy address pins one server.

Try it yourself

Reading about a queue growing is not the same as watching one. These Lessons are free and run in your browser. No sign-up is needed.

Break a pool with round robin, fix it with least connections, then crash a server and watch the balancer route around it.

Frequently asked questions

What does a load balancer do?

A load balancer gives users one address and spreads their requests over several servers. It accepts each request, picks a backend, forwards it and passes the response back. It runs no application code. It also stops sending traffic to servers that fail their health checks.

Which load balancing algorithm should I use?

If your servers are identical and your requests cost about the same, round robin is fine. If servers differ in size or requests vary, use least connections. Use weighted round robin if you want explicit control and will keep the weights up to date. Use IP hash only when you need a client to stick to one server.

What is the difference between L4 and L7?

An L4 balancer works on TCP connections. It sees addresses and ports, not the HTTP request, so it is fast and cheap and works for any protocol. An L7 balancer reads the HTTP request, so it can route by path, terminate TLS, retry and run real health checks, at a higher CPU cost per request.

Is the load balancer a single point of failure?

It can be. If one balancer sits in front of every server and it crashes, nothing gets through. Run a pair that share one address, or use a managed balancer that already spans several zones.

Related guides

free, no obligation

Tell us the idea. We’ll plan it with you.

Majid reads it, asks what he needs to know, then sends a written plan with a fixed price. If we’re not the right team, he’ll say so.

Rather talk? Book the free 20-minute call
or email hello@bytecrest.dev

WhatsApp us+92 348 183 7238

Free, no obligation. We never share your idea. Privacy