Tech_Interview_Prep

Load Balancing

Distributing traffic across multiple backend instances — algorithms, health checks, and layer 4 vs layer 7 balancing.

What it is

A load balancer distributes incoming traffic across multiple backend instances — both for scaling horizontally beyond what one instance can handle, and for routing around instances that have failed.

Key points

  • Layer 4 vs. Layer 7 load balancing: Layer 4 balances based on IP/port information only (faster, protocol-agnostic); Layer 7 balances based on application-level content (e.g. HTTP path or header), enabling smarter routing decisions at some added cost.
  • Load balancing algorithms: round-robin (simple, even distribution), least-connections (accounts for backends already under load), and consistent hashing (routes the same client/key to the same backend, useful for cache locality) each fit different workload characteristics.
  • Health checks: a load balancer continuously probes backend health and automatically stops routing traffic to an unhealthy instance — this is what turns a load balancer into a reliability tool, not just a traffic-distribution one.
  • Load balancers are frequently also the TLS termination point — decrypting HTTPS traffic once at the edge rather than requiring every backend instance to handle TLS itself.