โ† Back to list

5 ๐‹๐จ๐š๐ ๐๐š๐ฅ๐š๐ง๐œ๐ข๐ง๐  ๐€๐ฅ๐ ๐จ๐ซ๐ข๐ญ๐ก๐ฆ๐ฌ ๐˜๐จ๐ฎ ๐Œ๐ฎ๐ฌ๐ญ ๐Š๐ง๐จ๐ฐ

When building systems that lots of people useโ€Šโ€”โ€Šlike websites, apps, or APIsโ€Šโ€”โ€Šload balancing becomes super important. Itโ€™s a common topicโ€ฆ

Md. Zakir Hossain ยท 2025-08-21 21:32 ยท 0 claps ยท 4.5 min read
#load-balancing #round-robins #weighted-round-robin #least-connections #ip-hash
Open on Medium โ†—

5 ๐‹๐จ๐š๐ ๐๐š๐ฅ๐š๐ง๐œ๐ข๐ง๐  ๐€๐ฅ๐ ๐จ๐ซ๐ข๐ญ๐ก๐ฆ๐ฌ ๐˜๐จ๐ฎ ๐Œ๐ฎ๐ฌ๐ญ ๐Š๐ง๐จ๐ฐ

5 Load Balancing Algo

5 Load Balancing Algo

When building systems that lots of people use โ€” like websites, apps, or APIs โ€” load balancing becomes super important. Itโ€™s a common topic in interviews and a must-have in real-world projects that need to scale smoothly.

Before we jump into the different types of load balancing algorithms, letโ€™s first understand what load balancing actually means.

โš–๏ธ What Is Load Balancing?

Imagine youโ€™ve built a popular food delivery app. One evening, thousands of users open the app at the same time to place orders. If all those requests go to a single server, itโ€™ll get overwhelmed โ€” just like one chef trying to cook every meal alone.

A load balancer acts like a smart kitchen manager. It spreads the incoming orders (requests) across multiple chefs (servers), making sure no one is overloaded and every customer gets their food quickly.

Now that youโ€™ve got the idea, letโ€™s explore the Top 5 Load Balancing Algorithms You Should Know โ€” with simple explanations and examples to help you understand how they work in practice.

1. Round Robin (The โ€œTake Turnsโ€ Method)

Round Robin is one of the easiest ways to balance traffic between servers. Think of it like taking turns in a game โ€” each server gets a request one by one, in a loop.

๐Ÿ› ๏ธ How It Works (Step-by-Step)

  • The load balancer keeps a list of all available servers.
  • When a new request comes in, it sends it to the next server in the list.
  • Once it reaches the last server, it starts again from the first โ€” just like a circle.

โœ… When to Use Round Robin

ยท When all servers have similar capacity and performance.

  • Tasks are short and roughly equal in size.
  • Great for static websites or simple services where no request is heavier than the others.

๐Ÿฝ๏ธ Real-Life Analogy

Imagine youโ€™re serving food to a line of guests. You have 3 chefs: Chef S1, S2, and S3. You hand out orders like this:

  • Order 1 โ†’ Chef S1
  • Order 2 โ†’ Chef S2
  • Order 3 โ†’ Chef S3
  • Order 4 โ†’ Chef S1
  • Order 5 โ†’ Chef S2
  • Order 6 โ†’ Chef S3

And so on. Everyone gets a fair share, and no one is left behind.

2. Least Connections (Pick the Least Busy Server)

Least Connections is a smarter way to balance traffic. Instead of just taking turns like Round Robin, it checks which server is the least busy right now โ€” and sends the next request there.

๐Ÿ› ๏ธ How it works?

  • The load balancer keeps track of how many requests each server is currently handling.
  • When a new request comes in, it sends it to the server with the fewest active connections.
  • This helps avoid overloading servers that are already working hard.

โœ… When to Use Least Connections

  • Requests vary in how long they take (like database queries or API calls).
  • Some tasks might โ€œstick aroundโ€ longer than others.
  • Great for dynamic apps where traffic isnโ€™t evenly spread.

๐Ÿฝ๏ธ Real-Life Analogy

Imagine youโ€™re at a bank with 3 counters:

  • Counter A has 2 customers
  • Counter B has 5 customers
  • Counter C has just 1 customer

Youโ€™d naturally go to Counter C, right? Thatโ€™s exactly what Least Connections does โ€” it finds the shortest line

3. Weighted Round Robin (Let the Stronger Servers Do More)

Weighted Round Robin is like Round Robin โ€” but smarter. Instead of giving each server an equal number of requests, it gives more work to the stronger servers that can handle it.

๐Ÿ› ๏ธ How It Works (Step-by-Step)

  • Each server is assigned a weight โ€” a number that shows how powerful it is.
  • Servers with higher weights get more requests.
  • The load balancer rotates through the servers, but gives extra turns to the ones with higher capacity.

โœ… When to Use Weighted Round Robin

  • Your servers have different CPU or memory sizes.
  • Youโ€™re running in a cloud setup with mixed instance types (some big, some small).
  • You want to use all your resources efficiently without overloading weaker servers.

๐Ÿฝ๏ธ Real-Life Analogy

Imagine youโ€™re handing out deliveries to drivers:

  • Driver S1 has a big van (weight 3)
  • Driver S2 has a small scooter (weight 1)

For every 4 deliveries:

  • S1 gets 3
  • S2 gets 1

This way, the stronger driver does more work, and the smaller one isnโ€™t overwhelmed.

4. IP Hash (Stick with the Same Server)

IP Hash is a load balancing method that makes sure each user keeps talking to the same server every time โ€” based on their IP address.

๐Ÿ› ๏ธ How It Works (Step-by-Step)

  • The load balancer takes the userโ€™s IP address and runs it through a hash function (a kind of formula).
  • That hash result decides which server the user gets connected to.
  • As long as the userโ€™s IP doesnโ€™t change, theyโ€™ll always be routed to the same server.

โœ… When to Use IP Hash

  • You need session persistence โ€” meaning the same user should always go to the same server.
  • Perfect for apps like:
  • ๐Ÿ›’ Shopping carts (so items donโ€™t disappear)
  • ๐Ÿ’ฌ Chat apps (so conversations stay consistent)

๐Ÿฝ๏ธ Real-Life Analogy

Imagine youโ€™re assigning lockers at a gym based on someoneโ€™s phone number:

  • Person with number 192.168.1.5 always gets Locker A
  • Person with number 192.168.1.6 always gets Locker B

Even if they come back tomorrow, theyโ€™ll get the same locker โ€” just like IP Hash keeps users tied to the same server.

5. Random (Just Roll the Dice)

Random is the most straightforward load balancing method. It doesnโ€™t try to be smart โ€” it just picks a server at random for each request.

๐Ÿ› ๏ธ How It Works (Step-by-Step)

  • The load balancer doesnโ€™t check how busy each server is.
  • It simply chooses one at random and sends the request there.
  • No tracking, no patterns โ€” just pure chance.

โœ… When to Use Random

  • All servers are similar in power and speed.
  • Youโ€™re working in a test environment or handling lightweight tasks.
  • Perfect when requests are quick and short-lived, and you donโ€™t need fancy logic.

๐Ÿฝ๏ธ Real-Life Analogy

Imagine youโ€™re tossing a coin to decide which delivery driver gets the next order. You donโ€™t care whoโ€™s busier or faster โ€” you just let luck decide:

  • Request โ†’ Driver S2
  • Request โ†’ Driver S3
  • Request โ†’ Driver S1
  • Request โ†’ Driver S1
  • Request โ†’ Driver S3

Totally random, but it works when everyoneโ€™s equally capable.

๐Ÿš€ Want to dive deeper? Iโ€™m planning follow-up posts on 10 key Load Balancing algorithms with real-life examples & use cases. Stay tuned!

โœจ Enjoyed this article? ๐Ÿ‘‰ Support my work by

[embed]Buy Me a Coffee โ˜•" or "Support My Work If you enjoy my articles, tutorials, and projects, you can support me by buying me a virtual coffee. Your support keepsโ€ฆzakirtech.gumroad.com

Your small gesture keeps me motivated to write more! ๐Ÿ’™


๋ฉ”ํƒ€๋ฐ์ดํ„ฐ
post_id
3f937e2a73c8
slug
load-balancing-algo-3f937e2a73c8
url
https://medium.com/@md.zakirhossain/load-balancing-algo-3f937e2a73c8
canonical_url
https://medium.com/@md.zakirhossain/load-balancing-algo-3f937e2a73c8
author_url
https://medium.com/@md.zakirhossain
status
ok
fetched_at
2026-06-25 07:00:49