Skip to solution
mediumSystem Design

What is a load balancer and what strategies does it use?

768 views
01

Understand the problem

Explain load balancing.

load-balancing
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

What Is a Load Balancer, and What Strategies Does It Use?

Target Audience: Junior & Senior Software Engineers preparing for System Design Interviews — no prior system design knowledge assumed. Difficulty: Easy to Medium

How to read this doc: Every concept is explained in plain language first. Right af

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Load balancing strategies: round robin vs least connections
Run Playground
class RoundRobinLB {
  constructor(servers) {
    this.servers = servers;
    this.index = 0;
  }

  next() {
    const server = this.servers[this.index % this.servers.length];
    this.index += 1;
    return server;
  }
}

class LeastConnectionsLB {
  constructor(servers) {
    this.servers = servers; // fixed order -- used to break ties deterministically
    this.connections = {};
    for (const s of servers) this.connections[s] = 0;
  }

  next() {
    let chosen = this.servers[0];
    for (const s of this.servers) {
      if (this.connections[s] < this.connections[chosen]) {
        chosen = s;
      }
    }
    this.connections[chosen] += 1;
    return chosen;
  }
}

const servers = ['A', 'B', 'C'];

const rr = new RoundRobinLB(servers);
const rrResult = [];
for (let i = 0; i < 7; i++) rrResult.push(rr.next());
console.log('Round robin:', rrResult);

const lc = new LeastConnectionsLB(servers);
const lcResult = [];
for (let i = 0; i < 5; i++) lcResult.push(lc.next());
console.log('Least connections:', lcResult);
console.log('Final connection counts:', lc.connections);
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 18 of 99 decoded in the System Design track. One more won't hurt.

Back to track