TechCoder.io / System Design

Load Balancing

Master L4 vs L7 load balancers, load balancing algorithms (Round-Robin, Least Connections, IP Hash), health checks, sticky sessions, and real-world tools like NGINX and AWS ALB.

By TechCoder TeamLast updated: 2026-10-17
In a Nutshell

Master L4 vs L7 load balancers, load balancing algorithms (Round-Robin, Least Connections, IP Hash), health checks, sticky sessions, and real-world tools like NGINX and AWS ALB. This hands-on tutorial focuses on practical implementation of load balancing concepts.

Load Balancing

A load balancer distributes incoming network traffic across multiple servers to ensure no single server becomes a bottleneck. It is the entry point to any scalable system.

Load Balancer Architecture Diagram

L4 vs L7 Load Balancers

Load balancers operate at different layers of the OSI model, with different capabilities and performance characteristics:

FeatureL4 (Network LB)L7 (Application LB)
Operates onTCP/UDP packetsHTTP/HTTPS content
Routing based onIP + PortURL, headers, cookies, content
SSL Termination❌ No (passes through)✅ Yes (handles TLS)
Content routing❌ No✅ Yes (path-based, host-based)
Performance⚡ Faster (less processing)Slightly slower
Use caseRaw TCP, UDP, gaming, DNSHTTP APIs, web apps
AWS productNLB (Network Load Balancer)ALB (Application Load Balancer)

Load Balancing Algorithms

PYTHON PLAYGROUND
⏳ Loading editor…

Health Checks

A load balancer must continuously monitor backend servers and remove unhealthy ones from rotation.

[!TIP] Implement three types of health endpoints in your services:

  • /health/live — Is the process alive? (Kubernetes liveness probe)
  • /health/ready — Is the service ready to receive traffic? (Kubernetes readiness probe)
  • /health — Full health status including dependencies (DB, cache, etc.)

Quiz

Quiz

Question 1 of 2

Which load balancing algorithm is best for WebSocket connections where some connections stay open for hours?

Round Robin — distributes evenly
Least Connections — routes new connections to the server with fewest active connections
IP Hash — ensures same client goes to same server

Official Resources

Key Takeaways

✅ L4 LB operates at network layer — fast, but can only route by IP/port.
✅ L7 LB sees HTTP content — enables path routing, SSL termination, A/B testing.
✅ Round Robin is simplest; Least Connections is best for variable request durations.
✅ IP Hash creates sticky sessions — only use it for legacy stateful apps.
✅ Health checks automatically remove failed servers — configure active (ping) + passive (error rate) checks.

What's Next?

Load balancers distribute traffic, but we can reduce load entirely with caching.
Next: Caching Strategies — Redis, CDN, eviction policies, and how Netflix serves millions with a tiny database load.