Load Balancing in Cloud

What is Load Balancing?

Load balancing is the process of distributing incoming network traffic across multiple servers to ensure no single server becomes overwhelmed, improving application availability, reliability, and performance.

Types of Load Balancers

Cloud providers offer different types of load balancers, including application load balancers that operate at the request level, and network load balancers that operate at the connection level, each suited to different traffic patterns.

Benefits of Cloud Load Balancing

Cloud load balancing enables automatic scaling, improves fault tolerance by rerouting traffic away from unhealthy servers, and helps applications handle sudden traffic spikes without downtime.

What Happens to a Single Request

It helps to follow one user request from start to finish:

  1. The user types the site address. DNS returns the address of the load balancer, not of any individual server.
  2. The load balancer receives the request on a listener, which is a configured protocol and port such as HTTPS on 443.
  3. If the listener handles HTTPS, the load balancer can terminate TLS here, decrypting the request so it can read the path and headers.
  4. Routing rules decide which backend pool (also called a target group) should handle it, for example /api/* to the API servers and everything else to the web servers.
  5. Within that pool, a balancing algorithm picks one healthy server.
  6. The server responds, and the load balancer passes the response back to the user.

Meanwhile, the load balancer keeps sending health checks to every server, such as a request to /health every few seconds. A server that fails several checks in a row is taken out of rotation until it recovers.

Balancing Algorithms Compared

AlgorithmHow It ChoosesWorks Best When
Round robinSends each new request to the next server in turnServers are identical and requests are similar in cost
Weighted round robinGives bigger servers a larger shareServers have different capacity
Least connectionsPicks the server with the fewest active connectionsRequests vary a lot in duration
Hash-basedUses a hash of client IP or other fields so the same client lands on the same serverSome affinity is needed without cookies

Layer 4 vs Layer 7 and Global Balancing

A network (layer 4) load balancer looks only at IP addresses, ports and protocol. It is fast and works for any TCP or UDP traffic, such as databases, game servers or custom protocols. An application (layer 7) load balancer understands HTTP, so it can route by URL path, host name or headers, rewrite requests and handle cookies. Choose layer 7 for websites and APIs that need smart routing, and layer 4 for raw throughput or non-HTTP traffic.

There is also global load balancing, which spreads users across regions, often using DNS or anycast, so a visitor in Mumbai reaches a nearby region and traffic fails over if a whole region has problems. Each cloud names these services differently, so check your provider's documentation for the exact options.

Common Load Balancing Mistakes

  • Shallow health checks. A check that only confirms the web server is running may pass even when the database connection is broken. Check a path that exercises real dependencies, but keep it light.
  • Storing sessions on one server. If a user's session lives in one server's memory, they get logged out when routed elsewhere. Store sessions in a shared cache or database instead of relying on sticky sessions alone.
  • Single zone backends. Spreading servers across availability zones is what makes the setup survive a zone outage.
  • No connection draining. Removing a server instantly can cut off in-flight requests; let it finish current work first.
  • Ignoring the real client IP. Behind a load balancer, apps see the balancer's address unless they read headers such as X-Forwarded-For.

Checklist: multiple zones, meaningful health checks, stateless servers, TLS configured, autoscaling linked to the backend pool, and access logs enabled.

Ready to Master Cloud Computing?

Join Uncodemy's industry-recognized Cloud Computing Course and build in-demand cloud skills with expert mentors.

Explore Cloud Computing Course