Load Balancing

A Load Balancer (LB) is the Traffic Cop of your infrastructure. It distributes incoming traffic across multiple healthy servers so no single server gets overwhelmed.

💡 Core Concepts

Why do we need it?

If you run a website on one server and it crashes, your site is down. If you run it on 3 servers, how does the user know which one to call? The LB gives a single entry point (DNS name) and routes traffic behind the scenes.

🚑 Health Checks

The LB constantly pings your servers ("Are you there?"). If a server fails to reply (e.g., CPU overload or crash), the LB stops sending traffic to it until it recovers.

Algorithms

Round Robin: Server 1, then 2, then 3, repeat.
Least Connections: Send to the server with the fewest active users.
IP Hash: User A always goes to Server 1 (Sticky).

đŸ•šī¸ Simulator: The Traffic Distributor

Algorithm: Round Robin (Traffic cycles 1 → 2 → 3)
đŸ‘Ĩ
Users
Internet
âš–ī¸
Load Balancer
ALB / NGINX
đŸ–Ĩī¸
Server A
Healthy
đŸ–Ĩī¸
Server B
Healthy
đŸ–Ĩī¸
Server C
Healthy
System Online. All servers registered healthy.

đŸ—ī¸ ALB vs NLB (The AWS Flavors)

Application Load Balancer (ALB)

Layer 7 (HTTP/HTTPS)

Smart. It looks inside the packet. It can route `/api` to Server A and `/images` to Server B. It handles SSL termination and is best for websites/APIs.

Network Load Balancer (NLB)

Layer 4 (TCP/UDP)

Fast. It doesn't look inside. It just forwards packets at lightning speed. It handles millions of requests per second. Used for gaming or extreme performance.