1 Load Balancing Algorithms

explain all 3 algos ? Round Robin, Least Connections, IP Hash

βš–οΈ ASG

ChatGPT said: You got it, Om! Let’s break down the three main load balancing algorithms you’ll come across in Kubernetes/EKS Ingress Controllers like NGINX πŸ‘‡

1️⃣ Round Robin

πŸ“Œ What it does: Distributes each new request to the next server in line, cycling through all available backends (pods).

πŸ” How it works:

  • 1st request β†’ Pod A
  • 2nd request β†’ Pod B
  • 3rd request β†’ Pod C
  • 4th request β†’ Pod A again … and so on.

βœ… Pros:

  • Simple and fair.
  • Great when all pods have similar load capacity.

❌ Cons:

  • Doesn’t account for current load (e.g., one pod may be busier).

2️⃣ Least Connections

πŸ“Œ What it does: Sends requests to the pod with the fewest active connections.

πŸ“‰ How it works:

  • Tracks how many active (in-flight) requests each pod has.
  • Routes new requests to the least busy pod.

βœ… Pros:

  • Better for long-running requests.
  • Dynamically balances based on real-time load.

❌ Cons:

  • Slightly more overhead (needs to track connections).
  • Not all ingress controllers support this out of the box.

3️⃣ IP Hash

πŸ“Œ What it does: Uses a hash of the client’s IP address to always send requests to the same backend pod.

πŸ” How it works:

  • Hash(IP) β†’ assigns a pod.
  • All requests from that IP go to the same pod (as long as the pod is alive).

βœ… Pros:

  • Helps with session persistence (sticky sessions).
  • Same user always hits the same pod β€” useful for caching.

❌ Cons:

  • Traffic may be uneven if certain IPs generate more load.
  • Fewer IPs = fewer hash buckets = imbalance.

🎯 Quick Comparison

AlgorithmLoad AwarenessSticky SessionsUse Case Example
Round Robin❌ No❌ NoSimple balanced traffic
Least Connectionsβœ… Yes❌ NoAPIs with varying request durations
IP Hash❌ Noβœ… YesChat apps, game servers, caching apps