Cloud & DevOps4 min read10 interview questions

Load balancers explained

How many servers share the work behind one address.

In one sentenceA load balancer is a traffic officer in front of your servers, sending each visitor to one that is free and healthy.

Think of it like thisIt is the host at a restaurant who seats each group at a table with space, and skips tables that are closed.

The big picture

Tap any step to see where to use it, how to use it and an example result.

Why have one

A single server can fail or be overwhelmed. With several servers behind a load balancer, one failing is not noticed, and you can add more as traffic grows.

How it chooses

Common rules are round robin (take turns), least connections (pick the least busy) and sticky sessions (keep a visitor on the same server). Health checks remove servers that stop answering.

Where it lives

Cloud providers offer managed load balancers, and software such as Nginx or HAProxy can do the same job. Some work with web addresses and paths, others only with raw connections.

Common mistakes

  • Keeping user sessions only in one server's memory, so changing servers logs the user out.
  • Having one load balancer with no backup. It becomes the single point of failure.
  • Setting health checks so loose that dead servers still get traffic.

Quick recap

  • One address in front of many servers
  • Health checks hide failures
  • Rules decide who gets each request
  • Keep session data outside individual servers

Try it yourself

Run two copies of a simple web server on different ports and put Nginx in front of both to share the requests.

Top 10 interview questions

Ordered from basic to advanced. Try answering out loud first, then open the answer.

  1. What is a load balancer?Basic

    A server or service that sits in front of several copies of an application and shares incoming requests between them, so no single copy is overloaded.

  2. Why use a load balancer?Basic

    For more capacity, for availability because traffic skips failed servers, and for easier updates because servers can be replaced one at a time.

  3. What is round robin?Basic

    The simplest method: send requests to each server in turn, first, second, third, then back to the first.

  4. What is a health check?Basic

    A regular test, such as requesting /health, to see whether a server is working. Servers that fail are removed from rotation until they recover.

  5. What other balancing algorithms exist besides round robin?Intermediate

    Least connections sends to the server with the fewest active connections. Weighted methods favour bigger servers. IP hash sends the same client to the same server.

  6. What is the difference between a layer 4 and a layer 7 load balancer?Intermediate

    Layer 4 balances by IP address and port without reading the content, so it is fast and simple. Layer 7 understands HTTP, so it can route by path, host or header and can handle things like cookies and TLS.

  7. What are sticky sessions and why can they be a problem?Intermediate

    They keep a user on the same server, usually through a cookie. They help when session data lives on that server, but make uneven load and failures worse. Storing sessions in a shared store avoids the need.

  8. What is TLS termination at the load balancer?Intermediate

    The load balancer decrypts HTTPS traffic and passes plain or re-encrypted traffic to the servers behind it. It centralises certificates and takes encryption work off the servers.

  9. How do you avoid the load balancer itself being a single point of failure?Advanced

    Run it as a redundant pair or cluster, with a shared virtual IP, DNS across several, or a managed cloud load balancer that is already spread across zones.

  10. What is the difference between a load balancer, a reverse proxy and an API gateway?Advanced

    A reverse proxy forwards client requests to backend servers. A load balancer is a reverse proxy focused on spreading traffic. An API gateway adds API features such as authentication, rate limiting and request transformation.

Back to Learn Hub

Guides are simplified on purpose. Tool names and details change, so check the official documentation before relying on a detail.