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
| Algorithm | Load Awareness | Sticky Sessions | Use Case Example |
|---|---|---|---|
| Round Robin | β No | β No | Simple balanced traffic |
| Least Connections | β Yes | β No | APIs with varying request durations |
| IP Hash | β No | β Yes | Chat apps, game servers, caching apps |
Related Topics
- 1 Application Load Balancer (ALB) - AWS ALB implementation
- 2 Network Load Balancer (NLB) - AWS NLB for TCP/UDP traffic
- 3 Target Groups - Backend configuration for load balancers