Weighted & Resource-Based Algorithms
Table of Contents + −
Plain round robin just goes around the servers in a circle: server 1, server 2, server 3, back to 1. That’s fair and simple, but it assumes something that’s often not true:
- It assumes every server is equally strong and equally free.
But what if one server is a powerful new machine and another is old and weak? Or one is already busy with heavy work while another is idle? Sending them the same amount of traffic is unfair, and it overloads the weaker one. The fixes are weighted and resource-based algorithms. They send traffic based on how strong or how busy each server is. Let’s see how.
🎯 The Problem With Treating Servers Equally
Round robin and plain least-connections work great when all servers are the same. But real systems often have:
- Different sized servers. You added a big new machine, but the old small ones are still running. They can’t handle the same load.
- Different current loads. One server is stuck on a slow, heavy task while others are free.
If you ignore this and spread traffic evenly, the weak or busy server falls behind. It gets slow, requests pile up, and users feel it. So we need ways to send more traffic to the servers that can handle more. That’s exactly what these two approaches do.
⚖️ Weighted Algorithms
A weighted algorithm gives each server a weight, which is just a number that says how much traffic it should get compared to the others. A stronger server gets a bigger weight.
The most common version is weighted round robin. Say you have:
- Server A (big machine): weight 3
- Server B (small machine): weight 1
Then for every 4 requests, 3 go to A and 1 goes to B. So A, the stronger one, does most of the work. Here’s the idea in plain terms:
Weights: A = 3, B = 1Requests: A, A, A, B, A, A, A, B, ...# A handles 3 out of every 4 requestsReading that: the bigger the weight, the more often that server gets picked. You set the weights based on how strong each server is.
Weights are set ahead of time
Weights are usually decided in advance, based on each server’s known power. They don’t change on their own. So weighted algorithms handle servers of different sizes, but they don’t react to how busy a server is right now.
📈 Resource-Based Algorithms
Resource-based algorithms go a step further. Instead of fixed weights, they look at what’s actually happening on each server right now and send the next request to the one in the best shape.
What they can watch:
- Current load, like how much of the CPU and memory each server is using.
- Response time, like which server is answering fastest at the moment.
- Active connections, like which server has the fewest requests in progress.
So if server B suddenly gets bogged down, a resource-based balancer notices and sends the next requests to the freer servers instead. It reacts live. A common example is “least response time”: send the next request to whichever server is currently answering quickest.
That diagram shows the resource-based idea: the balancer checks the live state and picks the server that’s most able to handle the request right now.
📊 Comparing the Approaches
Here’s how these stack up against plain round robin.
| Algorithm | Decides by | Reacts to live load? | Best for |
|---|---|---|---|
| Round Robin | Simple rotation | No | Equal servers, equal work |
| Weighted | Preset weights | No | Servers of different sizes |
| Resource-Based | Live load, response time | Yes | Uneven, changing workloads |
🧭 When to Use Which
A simple way to choose:
- All servers equal and work is steady? Plain round robin is fine.
- Servers are different sizes, but each request is roughly similar? Weighted.
- Load swings around and some requests are much heavier than others? Resource-based, since it reacts to what’s happening now.
More reacting means more checking
Resource-based algorithms are the smartest, but they have to keep checking each server’s state, which is extra work. Use them when load really is uneven. If your servers and traffic are steady, simpler is better.
⚠️ Common Mistakes and Misconceptions
A few things to keep straight:
- “Weighted algorithms react to busy servers.” They don’t. Weights are set in advance based on server size. If a heavy-weighted server suddenly gets busy, weighted routing still keeps sending it lots of traffic. You need resource-based for that.
- “Resource-based is always best.” It’s the smartest, but it costs more because it constantly checks server state. For equal, steady servers it’s overkill.
- “Bigger weight means the server is more important.” No. Weight just means capacity, how much traffic it can take. It’s about strength, not priority.
🧩 What You’ve Learned
Nice work. Here’s the recap:
- ✅ Round robin assumes all servers are equal and free, which often isn’t true.
- ✅ Weighted algorithms give each server a preset weight, sending more traffic to stronger servers.
- ✅ Resource-based algorithms watch live load and response time, and send requests to the freest server right now.
- ✅ Weighted handles different server sizes; resource-based reacts to changing load, but costs more to run.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
How do weighted algorithms decide where traffic goes?
Why: Weighted algorithms use fixed weights set in advance. A stronger server gets a higher weight and more traffic.
- 2
Which approach reacts to how busy each server is right now?
Why: Resource-based algorithms watch live data like load and response time, and send requests to the freest server.
- 3
When is plain round robin a poor choice?
Why: Round robin treats everyone equally, so it overloads weaker or busier servers when things are not equal.
- 4
Does a weighted algorithm react when a server suddenly gets busy?
Why: Weights do not change on their own. To react to live load, you need a resource-based algorithm.
🚀 What’s Next?
You’ve seen the smarter ways to pick a server. Let’s round out load balancing.
- Least Connections Algorithm is a simple step toward reacting to load.
- Sticky Sessions show how to keep one user on the same server.
Get these down and you’ll understand the full range of how load balancers decide.