How does load balancing work?
A load balancer distributes incoming network traffic across a pool of resources that support an application [1]. An algorithm decides where each request goes. Static algorithms ignore the current state of the servers: round robin takes them in turn, weighted round robin sends more traffic to servers with higher weights, and IP hash picks a server from the client's IP address. Dynamic algorithms look at live state; least connection sends the request to the server with the fewest active connections [1]. Load balancers also run health checks, spotting a failing server and redirecting traffic to healthy ones [1].
What is the difference between Layer 4 and Layer 7 load balancing?
It comes down to how much of the request the balancer reads. On Google Cloud, Application Load Balancers are proxy-based Layer 7 balancers suited to HTTP and HTTPS, and they can route on details such as HTTP headers and URIs [2]. Network Load Balancers work at Layer 4 and handle TCP, UDP and other IP protocol traffic [2]. Scope varies too: a global load balancer supports backends in multiple regions, a regional one supports backends in a single region [2].
What does load balancing buy you?
Picture an online shop spreading sale-day traffic across three servers. If one fails, the load balancer routes around it to the other two, and the same mechanism lets you take a server down for maintenance without an outage [1]. AWS also credits load balancing with preventing bottlenecks, making it easy to add or remove servers as demand changes, and helping mitigate DDoS attacks [1].