What does round-robin scheduling do?
What Round-Robin Scheduling is
Round-Robin is an algorithm where tasks, requests or users are served in turn, evenly and cyclically, with no priority.
In other words:
"everyone gets a turn".
An example of how it works
Imagine you have 3 servers:
Server A
Server B
Server CAnd a stream of requests arrives:
R1, R2, R3, R4, R5, R6, ...
With Round-Robin, they distribute like this:
R1 → Server A
R2 → Server B
R3 → Server C
R4 → Server A
R5 → Server B
R6 → Server C
and so onAfter the last server, the queue wraps back to the first, a "round".
1. Where Round-Robin is used
| Area | Application |
|---|---|
| Load balancing | Distributes HTTP requests across servers |
| Operating systems | A task scheduler for processes and CPU threads |
| Node.js Cluster / PM2 | Distributes incoming connections across workers |
| Network load balancers | NGINX, HAProxy, AWS ELB, and others |
| Databases and queues | Evenly spreads load across replicas |
2. How Round-Robin works in Node.js Cluster
Node.js uses Round-Robin when balancing across workers (cluster or PM2):
- The master process listens for incoming connections (for example, HTTP port 3000).
- Every new request goes to the next worker in line.
- Once the queue reaches the end, the cycle starts over.
So:
Every worker gets roughly the same number of requests, which spreads CPU load evenly.
Example:
import cluster from 'cluster';
import http from 'http';
import os from 'os';
if (cluster.isPrimary) {
const numCPUs = os.cpus().length;
console.log(`Master ${process.pid} starting ${numCPUs} workers`);
for (let i = 0; i < numCPUs; i++) cluster.fork();
} else {
http.createServer((req, res) => {
res.end(`Response from worker ${process.pid}`);
}).listen(3000);
}Node.js distributes requests across workers round-robin on its own. For example:
Request 1 → PID 1001
Request 2 → PID 1002
Request 3 → PID 1003
Request 4 → PID 10013. Round-Robin in Nginx
nginx.conf
upstream backend {
server 127.0.0.1:3001;
server 127.0.0.1:3002;
server 127.0.0.1:3003;
}
server {
listen 80;
location / {
proxy_pass http://backend;
}
}Nginx uses round-robin by default, so requests distribute the same way:
#1 → 3001
#2 → 3002
#3 → 3003
#4 → 3001
...4. Features and advantages
| Advantage | Description |
|---|---|
| Simplicity | Implementable in a few lines |
| Evenness | Every node gets the same load |
| Predictability | No randomness or priority |
| Stateless | No client data needs to be stored |
| High speed | Minimal computational overhead |
5. Round-Robin's drawbacks
| Drawback | Description |
|---|---|
| Ignores server capacity | A weaker server still gets the same share of requests |
| No sticky sessions | One user can land on a different server on every request |
| Ignores real-time load | Even an overloaded server keeps getting new requests |
| A poor fit for long-lived connections (WebSocket) | Can overload individual workers |
6. Variants of the algorithm
To fix these issues, there are improved versions of Round-Robin:
| Algorithm | The difference |
|---|---|
| Weighted Round-Robin | Servers get a "weight" (more powerful ones get more traffic) |
| Dynamic Round-Robin | Accounts for a server's current load |
| Least Connections | Sends new requests to the server with the least activity |
| IP Hash | The same client always lands on the same server (sticky sessions) |
7. A real-life analogy
Picture a line of customers at a bank with 3 tellers:
- the first serves customer 1,
- the second serves customer 2,
- the third serves customer 3,
- the next customer goes back to the first teller.
That's Round-Robin, each teller (server) gets a customer in turn.
Summary
| Criterion | Description |
|---|---|
| What it does | Distributes tasks or requests in turn and cyclically |
| Where it's used | Load balancing, schedulers, operating systems |
| Type | A simple, deterministic algorithm |
| Advantages | Simple, even, efficient |
| Drawbacks | Ignores server capacity and load |
| Used in | Node.js Cluster, PM2, Nginx, HAProxy, AWS ELB |
Conclusion:
Round-Robin Scheduling is a "take turns" algorithm that evenly spreads load across every available node (process, thread, or server).
It's simple, fast and efficient, which is why it's the default in load balancers like Nginx, HAProxy, PM2 and Node.js Cluster.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.