Application Load Balancing
The Application Load Balancer acts at Layer 7 (the application layer) of the OSI model, so it can make routing decisions based on the URL. It distributes HTTP and HTTPS traffic to backends on Compute Engine, GKE, Cloud Storage, Cloud Run, and App Engine, as well as external backends reached over the internet or hybrid connectivity.
It comes in two deployment types: external and internal (internal is covered later in the module).
- Global external and classic ALBs are implemented with Google Front Ends (GFEs) distributed globally. In the Premium tier they do multi-region load balancing, sending traffic to the closest healthy backend with capacity and terminating HTTP(S) as close to the user as possible.
- Regional external ALBs use the open-source Envoy proxy for advanced traffic management.
These can be deployed in one of three modes: global, regional, or classic.
Deployment modes
Request-path architecture
The request flows through four pieces:
- An external forwarding rule specifies an external IP address, port, and a target HTTP(S) proxy. Clients connect to this IP and port.
- The target HTTP(S) proxy receives the request, evaluates it against the URL map to make routing decisions, and can authenticate with SSL certificates.
- A backend service distributes requests to healthy backends. Global external ALBs also support backend buckets.
- One or more backends are attached to the backend service (or backend bucket).
Global external ALB end to end
Mapping those pieces onto concrete resources shows why the global external ALB is a single global front end over regional backends. The client reaches one anycast IP; the global forwarding rule hands off to a target proxy, which consults the URL map and selects a backend service; a health check gates which instances receive traffic; and firewall rules must admit the load balancer before it can reach the managed instance groups, which live in subnetworks across two regions of one VPC.
One anycast IP fronts backends in multiple regions - the load balancer sends each request to the closest healthy region with capacity. You still create the managed instance groups per region (and open firewall rules for the health-check and client traffic ranges) before any backend is reachable.
A global external ALB frontend can serve both IPv4 and IPv6 on the same load balancer (one forwarding rule per IP version). Client IPv6 requests terminate at the global load-balancing layer and are then proxied over IPv4 to your backends - so the backends themselves never need IPv6.
HTTPS: target proxy and SSL certificates
An HTTPS Application LB has the same structure as an HTTP one but swaps in a target HTTPS proxy in place of the target HTTP proxy.
- Uses a target HTTPS proxy (not a target HTTP proxy).
- Requires at least one signed SSL certificate installed on the target HTTPS proxy.
- Client SSL sessions terminate at the load balancer - the proxy decrypts, then talks to backends.
- Supports the QUIC transport layer protocol.
To serve HTTPS you first create an SSL certificate resource holding the certificate information, then attach it to the target proxy.
- Required for an HTTPS Application Load Balancer.
- A target proxy holds up to 15 SSL certificates.
- One SSL certificate resource per certificate.
QUIC lets the client-to-load-balancer leg start faster, eliminates head-of-line blocking in multiplexed streams, and survives a client IP change (connection migration - handy on mobile). It is a property of the front-end HTTPS proxy, not the backend service.
An SSL certificate resource is used only with load-balancing proxies - a target HTTPS proxy or a target SSL proxy. Passthrough Network LBs terminate nothing, so they never take one.
Backend services
A backend service bundles a health check, session affinity, a timeout, and one or more backends.
- Health check - polls attached instances at configured intervals; only instances that pass receive new requests. Unhealthy instances are cut off until they recover.
- Session affinity (optional) - overrides the default round-robin so all requests from one client go to the same VM.
- Timeout setting - 30 seconds by default; how long the backend service waits before treating the request as a failure.
- One or more backends, each with an instance group, a balancing mode, and a capacity scaler.
The 30-second default is a fixed timeout on the whole request, not an idle timeout. If you need longer-lived connections, raise this value.
Application Load Balancing distributes requests round-robin among available instances. Turning on session affinity attempts to pin a client to the same VM - it is a best-effort override, not a guarantee.
Backends: instance group, balancing mode, capacity scaler
- An instance group holds the VMs - a managed instance group (with or without autoscaling) or an unmanaged instance group.
- A balancing mode tells the LB when a backend is at full usage, based on CPU utilization or requests per second (RPS).
- A capacity scaler is a ceiling percentage that interacts with the balancing mode.
- Target 80% CPU: balancing mode
80% CPU utilization, capacity100%. - Cut utilization in half: leave balancing mode at
80% CPU utilization, set capacity50%.
If all backends for a backend service in a region hit full usage, new requests are automatically routed to the nearest region that can still handle them.
Changes to backend services propagate through the network over several minutes - don't be surprised if an update doesn't take effect immediately.
Backend buckets
A backend bucket lets an external Application LB serve content straight from a Cloud Storage bucket. The URL map routes each request path to either a backend service (dynamic content on VMs/containers) or a backend bucket (static content in Cloud Storage).
Network endpoint groups (NEGs)
A network endpoint group (NEG) is a configuration object naming a group of backend endpoints or services. NEGs are backends for some load balancers and for Traffic Director; a common use is routing traffic to services running in containers.
Zonal and internet NEGs define how an endpoint is reached, whether it is reachable, and where it is. A serverless NEG carries no endpoints - it just points at a serverless service in its own region.