Interview Prep/DevOps Fundamentals/Infrastructure & cloud basics

What is a load balancer, and why is it used?

BeginnerConceptInfrastructure & cloud basics
Answer

In one line: A load balancer sits in front of a group of servers and spreads incoming traffic across them, so no single server is overloaded and users keep being served even if some servers fail.

What a load balancer does:

  1. Distributes traffic across healthy instances.
  2. Health checks — regularly calls something like /health on each instance and stops sending traffic to unhealthy ones.
  3. High availability — spreads traffic across availability zones.
  4. Enables scaling — new instances are added to the pool automatically.
  5. TLS termination — handles HTTPS certificates so apps don't have to.
  6. Zero-downtime deployments — shifts traffic between old and new versions (rolling, blue/green, canary).

Layer 4 vs Layer 7:

Layer 4 (transport) Layer 7 (application)
Looks at IP and TCP/UDP port HTTP details: path, host, headers, cookies
Can route /api and /images differently? No Yes
Examples AWS NLB, Azure Load Balancer AWS ALB, Azure Application Gateway, Nginx, HAProxy, Envoy
Strength Very fast, any TCP protocol Smart routing, WAF integration

Common algorithms: round robin, least connections, weighted (useful for canaries), IP hash / sticky sessions.

In Kubernetes:

  • A Service of type LoadBalancer creates a cloud load balancer.
  • An Ingress controller or Gateway API implementation (for example NGINX, AWS Load Balancer Controller, Envoy Gateway) provides Layer 7 routing to many services through one load balancer.

Example: an ALB receives https://shop.example.com, terminates TLS, sends /api/* to the API target group and /* to the front-end, across three AZs, skipping any instance whose health check fails.

Tip for interviews: explain health checks and L4 vs L7 — those are the usual follow-up questions.

All DevOps Fundamentals questions

More on Infrastructure & cloud basics