Round Robin Load Balancing
Table of Contents + â
Say your app got popular overnight. One server canât handle all the traffic anymore, so you add a few more. Now youâve got a new question.
- You have, letâs say, three servers sitting ready.
- A flood of requests is coming in from users.
- Somebody has to decide which request goes to which server, right?
That somebody is the load balancer, the piece in front of your servers that hands out the incoming traffic. And the simplest way it can share that traffic is an algorithm called round robin. Letâs see exactly how it works.
đ What is Round Robin?
Round robin is the most basic way to spread requests across servers. Hereâs the idea in one line.
- The load balancer sends each new request to the next server in turn, and when it reaches the last server, it loops back to the first one.
- Thatâs it. It just goes around the circle, one server at a time, over and over.
- Think of it like dealing cards. You donât give all the cards to one player, right? You go one card to each person, around the table, then start again from the first.
So with three servers, the very first request goes to Server 1, the next to Server 2, the next to Server 3, and then the fourth request comes back around to Server 1. Hereâs that rotation as a picture.
And hereâs the same thing as a table, so you can see the pattern clearly.
| Request number | Goes to server |
|---|---|
| Request 1 | Server 1 |
| Request 2 | Server 2 |
| Request 3 | Server 3 |
| Request 4 | Server 1 (back to the start) |
| Request 5 | Server 2 |
See the loop? After Server 3, it just starts over from Server 1. The load balancer doesnât ask any questions, it just keeps the rotation going.
âď¸ Weighted Round Robin
Plain round robin treats every server the same. But what if your servers arenât the same? Maybe one is a beefy machine and another is a small one. Thatâs where the weighted version comes in.
- Weighted round robin lets you give each server a weight, which is just a number that says how big a share of traffic it should get.
- A stronger server gets a higher weight, so it receives more requests in each cycle.
- A weaker server gets a lower weight, so it receives fewer.
Letâs make it concrete. Say Server 1 is powerful and you give it a weight of 3, while Server 2 is small and gets a weight of 1.
- Out of every four requests, three go to Server 1 and one goes to Server 2.
- So the rotation might look like: Server 1, Server 1, Server 1, Server 2, then back to the start.
- The big server pulls more weight, the small one isnât overloaded, and everyone stays happy.
When weighted helps
Use weighted round robin when your servers have different capacity. If theyâre all the same size, plain round robin is enough and thereâs no reason to bother with weights.
⥠Why Itâs Popular
Round robin shows up everywhere as a default, and there are good reasons for that.
- Itâs dead simple. The logic is just âsend to the next one, then loopâ. You can explain it in a single sentence, and itâs easy to build.
- It keeps no state. The load balancer doesnât have to track how busy each server is or remember anything about past requests. It just counts to the next slot.
- It spreads load evenly when your servers are similar. If every server is the same size and every request takes about the same effort, traffic gets shared nice and fairly.
So for a lot of everyday setups, where the servers match and the requests are roughly equal, round robin just works. No fuss.
â ď¸ Where It Falls Short
Now hereâs the catch, and this is the part interviewers love to dig into. Round robin makes one big assumption.
- It assumes all servers and all requests are equal. It doesnât actually look at any of them.
- But requests are not equal. One request might be a quick âshow the homepageâ, and another might be a heavy âgenerate this giant reportâ.
- Imagine the heavy requests keep landing on the same server by the luck of the rotation. That server gets buried while the others sit half-idle.
And the deeper problem is this.
- Round robin doesnât know the current load on any server. It canât tell that Server 2 is already drowning.
- Itâll happily send the next request to Server 2 anyway, just because itâs Server 2âs turn.
- So a slow or struggling server keeps getting fed, even when itâs the last one that should.
Thatâs the trade-off for being so simple. Itâs blind. It counts turns, not actual work.
đ§Š When to Use It
So when should you reach for round robin, and when should you look elsewhere?
- Reach for it when your servers are similar in size and your requests cost about the same. Thatâs its sweet spot, simple and effective.
- If servers differ in power, use weighted round robin instead, so the bigger ones carry more.
- But if request costs vary a lot, or some requests run long while others are quick, round robin starts to struggle. In that case, consider an algorithm like least connections, which sends each request to whichever server is handling the fewest right now.
The rule of thumb is easy. Equal servers and equal requests, round robin is great. The more uneven things get, the more youâll want something smarter.
â ď¸ Common Mistakes and Misconceptions
A couple of things trip people up with round robin. Letâs clear them out.
- âRound robin balances actual load.â No, it doesnât. It only counts in turn. It has no idea how busy any server actually is, it just hands out requests one after another.
- âIt accounts for server power.â Plain round robin treats every server the same. Only the weighted version knows about server strength, and only because you told it the weights yourself.
- âEven traffic means even load.â Sending the same number of requests to each server isnât the same as giving each server the same amount of work. A few heavy requests can tip the balance fast.
đ ď¸ Design Challenge
Try this one on your own to test yourself.
Youâre running four servers behind a round robin load balancer. Three of them are equal-sized, but one is twice as powerful as the rest.
- First, explain what goes wrong if you use plain round robin here.
- Then, pick weights for each server so the powerful one gets a fair share of the extra traffic.
- Finally, describe one kind of request pattern that would make even weighted round robin a poor fit, and say what youâd switch to.
Work through it out loud, the way you would in an interview. Thatâs exactly the reasoning they want to see.
đ§Š What Youâve Learned
You can now explain how the simplest load balancing algorithm works. Hereâs what youâve picked up.
- â Round robin sends each request to the next server in turn, then loops back to the start.
- â Weighted round robin gives stronger servers a bigger share by assigning weights.
- â Itâs popular because itâs simple, stateless, and spreads load evenly across similar servers.
- â It falls short because it ignores real-time load and assumes all servers and requests are equal.
- â Use it for similar servers and similar request costs, and reach for least connections when load is uneven.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
How does round robin pick a server for each request?
Why: Round robin simply rotates through the servers in order and starts over after the last one.
- 2
Does round robin look at how busy each server is?
Why: Round robin is stateless and blind to load, so it keeps handing out requests in rotation no matter how busy a server is.
- 3
What does weighted round robin add?
Why: Weighted round robin assigns each server a weight so more powerful machines receive more requests per cycle.
- 4
What is a good alternative when request costs vary a lot?
Why: Least connections sends each request to the least busy server, so it handles uneven request costs better than round robin.
đ Whatâs Next?
Round robin is your starting point for load balancing. From here, you can go deeper into smarter algorithms and the bigger picture.
- Least Connections Algorithm sends each request to the server with the fewest active connections, so it reacts to real load.
- Load Balancer Architecture zooms out to show where the load balancer sits and how it fits into a full system.
Once youâve got those, youâll know not just how to share traffic, but how to share it intelligently.