GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
System designLoad balancing

Load balancing

L4 vs L7 balancers, routing algorithms, health checks, and avoiding the balancer itself becoming a single point of failure.

beginner 10 min read 4 interview questions

On this page

1/5
  1. 01What a load balancer does
  2. 02Routing algorithms
  3. 03Avoiding a single point of failure
  4. 04Interview questions
  5. 05Quick check
Back to top

What a load balancer does

A load balancer sits in front of a pool of servers and spreads requests across them. It also runs health checks and stops sending traffic to servers that fail them, which lets you deploy, scale and survive crashes without users noticing.

Layer 4 (transport)Layer 7 (application)
SeesIP addresses and portsHTTP method, path, headers, cookies
Can route byConnectionURL path, host, header, user
SpeedVery fast, little processingMore work per request
Extras—TLS termination, compression, caching, auth, rate limiting

Routing algorithms

AlgorithmHow it picksGood for
Round robinNext server in turnIdentical servers, similar requests
Weighted round robinIn turn, in proportion to weightsMixed server sizes
Least connectionsServer with fewest open connectionsRequests of very different lengths
Least response timeFastest recent responsesUneven or noisy servers
IP / key hashhash(client or key) mod NAffinity, such as keeping a user on one cache shard
Consistent hashingPosition on a hash ringAffinity that survives adding or removing servers
Power of two choicesPick two at random, take the less loadedLarge pools; near-optimal with little state

Plain hash mod N remaps almost every key when N changes. Consistent hashing moves only about 1/N of the keys; see the sharding module.

Avoiding a single point of failure

A single load balancer is itself a single point of failure. Common fixes: an active-passive pair sharing a virtual IP (the passive one takes over on a missed heartbeat), several active balancers behind DNS, or a managed cloud balancer that's redundant across availability zones.

Global traffic is usually split first by DNS (GeoDNS or anycast) to the nearest region, then by regional load balancers to servers.

A request through a load balancer

1/5
ClientDNSnearest regionLoad balancerhealth checksApp server AApp server BApp server Cunhealthy

The client resolves the domain. DNS returns the address of the load balancer in the nearest region.

See it animated

Hash functionsPriority queue

Interview questions

Try answering out loud first, then open the model answer.

Q1What's the difference between an L4 and an L7 load balancer?intermediate

L4 balancers route TCP/UDP connections using IPs and ports, without looking at the payload: fast and protocol-agnostic. L7 balancers understand HTTP, so they can route by path or header, terminate TLS, and add features like caching and rate limiting, at more cost per request.

Q2Which algorithm would you use when some requests take 10 ms and others 10 s?intermediate

Least connections (or least outstanding requests). Round robin would keep sending new work to a server stuck on long requests; counting open connections approximates real load.

Q3How does a load balancer know a server is unhealthy?beginner

Health checks: it periodically calls an endpoint (or opens a connection) and marks a server down after several failures, and up again after several successes. Passive checks also watch real traffic for errors and timeouts.

Q4How do you make the load balancer highly available?intermediate

Run at least two. Active-passive pairs share a virtual IP that moves on failure; active-active setups put several balancers behind DNS or anycast. Cloud balancers do this for you across zones.

Quick check

Question 1

1.Which balancer can route /api/* and /images/* to different pools?

Question 2

2.Health checks are used to…

Question 3

3.Why prefer consistent hashing over hash mod N for cache affinity?

0 of 3 answered

Scalability basicsCaching
Log inStart free