1. 🧠 What is a Load Balancer?
✅ Definition:
A load balancer is a device or software that distributes incoming network traffic across
multiple servers. The goal is to ensure no single server gets overwhelmed and to maximize
reliability, availability, and performance.
2. ⚙️What is a Network Load Balancer (NLB)?
✅ Definition:
A Network Load Balancer (NLB) operates at Layer 4 (Transport Layer) of the OSI model. It
uses information from the TCP/UDP headers (like IP address and port number) to decide how
to route traffic.
📌 Simply put: An NLB forwards connections to servers based on network-level data, not on the
content of the requests.
3. 📊 Why Use a Load Balancer?
High Availability – Keeps your service running even if one or more servers go down.
Scalability – Handles increased traffic by distributing it to more servers.
Performance Optimization – Reduces latency and avoids overloading any one server.
Failover – Redirects traffic if a server fails.
Maintenance Without Downtime – You can update or fix servers without affecting
users.
4. 🔍 Types of Load Balancers
Type OSI Layer Traffic Type Example
Network Load Balancer Layer 4 TCP/UDP AWS NLB, HAProxy
Application Load Balancer
Layer 7 HTTP/HTTPS AWS ALB, NGINX
(ALB)
Multiple Cloudflare, Google Cloud Load
Global Load Balancer Across regions
layers Balancer
For now, we're focusing on Network Load Balancers.
5. How Does a Network Load Balancer Work?
Step-by-Step:
1. Client sends request → to a single public IP (NLB).
2. NLB receives the request → inspects TCP/UDP headers.
3. NLB chooses a backend server using a load balancing algorithm.
4. NLB forwards the request to the chosen server.
5. Server processes the request and responds through the NLB.
Think of the NLB as a smart traffic cop at a network junction.
6. 🧮 Common Load Balancing Algorithms
Algorithm Description
Round Robin Each server gets requests in turn.
Least Connections Server with the fewest current connections is chosen.
IP Hash A hash of the client’s IP determines which server to use.
Weighted Round Robin Servers are assigned weights; more powerful servers get more traffic.
7. 🔐 Health Checks
A Network Load Balancer regularly checks if backend servers are healthy and responsive.
If a server fails a health check, the NLB stops sending traffic to it.
Health checks use protocols like TCP, HTTP, or HTTPS.
8. 🧱 Key Features of Network Load Balancers
Feature Description
Layer 4 Routing Based on IP address and TCP/UDP port.
High Performance Can handle millions of requests per second.
Low Latency Designed for very fast processing.
Static IP Keeps the same IP address, useful for DNS and firewall rules.
Feature Description
Zonal/Regional Can be deployed in one or multiple availability zones.
9. 🌐 Real-World Examples
AWS Network Load Balancer
o Designed for extreme performance.
o Supports TCP, UDP, and TLS traffic.
o Integrated with auto-scaling and health checks.
HAProxy (High Availability Proxy)
o Open-source.
o Can be configured as L4 or L7 load balancer.
F5 Big-IP
o Hardware and software load balancer.
o Popular in large enterprise networks.
10. 🆚 NLB vs ALB vs CLB
Feature NLB ALB Classic LB
OSI Layer 4 7 4&7
Use Case High performance, TCP/UDP HTTP/HTTPS routing Legacy systems
Speed Very fast Slower than NLB Slower
Protocols TCP, UDP, TLS HTTP, HTTPS All basic
Content-based routing ❌ ✅ ❌
11. 📉 What Happens Without a Load Balancer?
One server handles all traffic.
Risk of overload, downtime, and slow performance.
No automatic failover.
No easy way to scale.
12. 📚 Summary
Network Load Balancers (NLBs) operate at Layer 4.
They distribute traffic based on IP and port.
They're ideal for low-latency, high-performance applications.
Use cases: gaming servers, real-time communications, microservices.
NLBs are not content-aware, unlike ALBs.
13. 🧠 Questions for Students
1. What layer of the OSI model does a Network Load Balancer work at?
2. How does an NLB determine where to route traffic?
3. What happens if one of the backend servers fails?
4. What are the benefits of using an NLB?
5. What’s the difference between an NLB and an ALB?
🧮 Common Load Balancing Algorithms – Explained
1. Round Robin
How it works: Distributes each incoming request to the next server in a circular order.
Use case: Simple and works well when servers have roughly equal power.
Example:
o Request 1 → Server A
o Request 2 → Server B
o Request 3 → Server C
o Request 4 → Server A (repeats)
2. Least Connections
How it works: Sends the new request to the server with the fewest active connections.
Use case: Useful when traffic varies a lot in duration (e.g., chat or video sessions).
Example:
o Server A (1 connection), Server B (2), Server C (0)
o Next request goes to Server C.
3. IP Hash
How it works: Uses a hash of the client’s IP address to determine which server gets the
request.
Use case: Ensures that a client always connects to the same server (good for session
persistence).
Example:
o Client 192.168.1.1 → hash → Server B
o Client 192.168.1.2 → hash → Server C
4. Weighted Round Robin
How it works: Similar to round robin but assigns weights to servers. More powerful
servers get more requests.
Use case: Environments with servers of different capacities.
Example:
o Server A (weight 3), B (weight 1), C (weight 2)
o Order: A, A, A, C, C, B (then repeat)
5. Random
How it works: Chooses a backend server at random for each request.
Use case: Very simple and sometimes effective in highly balanced environments.