ALB, NLB, and Target Groups

Topics Covered

Choosing ALB or NLB

What an ALB does

What an NLB does

Deciding between them

The Gateway Load Balancer

Classic Load Balancers

Internet facing and internal

Cost model

Elastic Load Balancing spreads incoming traffic across targets such as EC2 instances, containers, IP addresses and Lambda functions, checks their health, and removes failing targets from rotation. Two load balancer types carry almost all new workloads: the Application Load Balancer, which works at layer 7 and understands HTTP, and the Network Load Balancer, which works at layer 4 and forwards TCP, UDP and TLS connections. A third, the Gateway Load Balancer, inserts security appliances transparently into traffic paths. Choosing between ALB and NLB is one of the first decisions for any service that accepts traffic, and the wrong choice shows up later as missing features, unexpected latency or awkward workarounds.

What an ALB does

An Application Load Balancer terminates HTTP and HTTPS connections from clients, parses each request, and decides where to send it using rules on host names, paths, headers, query strings, methods and source addresses. It opens its own connections to targets, so a target sees the load balancer's address as the source and learns the client's address from the X-Forwarded-For header. Because it understands requests, an ALB can route different paths to different services, return fixed responses and redirects, authenticate users through OIDC or Cognito before requests reach the application, and integrate with AWS WAF for request filtering. It supports HTTP/2 and gRPC to clients and to targets, and WebSockets.

ALB addresses are not fixed. The DNS name of an ALB resolves to the addresses of its current nodes, and those change as AWS scales the fleet, replaces nodes or moves capacity between zones. Clients must therefore always connect through the DNS name and respect its short time to live, never by caching or hard coding an address. Clients that resolve once at startup, such as some JVM configurations that cache DNS indefinitely, eventually send traffic to addresses that no longer belong to the load balancer, and the failures appear random. Setting a sane DNS cache time in the runtime avoids this.

What an NLB does

A Network Load Balancer forwards connections without parsing the application protocol. For TCP it chooses a target per connection using a flow hash of source and destination addresses, ports and protocol, and all packets of that connection go to the same target. By default it preserves the client's source address, so targets see the real client, and it can handle millions of requests per second with very low added latency. Each NLB node has a static IP address per zone, and an Elastic IP can be assigned to each, which matters for clients that allow list addresses. NLBs also support UDP, TLS termination and PrivateLink, which exposes a service to other VPCs and accounts.

The ALB read each request and sent /api and /images to different services. The NLB hashed each connection and never looked inside.

NLBs also handle client source addresses differently depending on target type. With instance targets, the client address is preserved by default; with IP targets, preservation is configurable, and when it is off the target sees the NLB's private address. When targets need the client address but preservation is not possible, such as through some PrivateLink paths, proxy protocol version 2 adds a header at the start of each connection carrying the original addresses, which targets must be configured to read. Turning on proxy protocol without updating the target breaks every connection, because the target sees unexpected bytes before the real protocol begins.

Deciding between them

Most HTTP services belong behind an ALB: path and host routing, WAF, authentication, HTTP/2 and request level metrics are worth more than the small latency the ALB adds. An NLB fits when the protocol is not HTTP, such as database proxies, MQTT, game servers or custom TCP protocols; when clients need static IP addresses to allow list; when the service must be exposed through PrivateLink; when the client's source address must reach the target unchanged; or when connection counts and throughput are extreme. Some designs combine both, placing an NLB with static addresses in front of an ALB target group, which gives fixed IPs and layer 7 routing together.

Latency differs too, though less than people expect. An ALB adds a few milliseconds per request for parsing, rule evaluation and the second connection to the target, which matters for chatty internal calls on hot paths but rarely for user facing pages. An NLB adds well under a millisecond. When teams measure, the choice usually comes down to features rather than speed, and the right question is which protocol features and integrations the service depends on, not which load balancer is faster in a benchmark.

The Gateway Load Balancer

A Gateway Load Balancer distributes traffic to fleets of virtual appliances such as firewalls and intrusion detection systems, using the GENEVE protocol to wrap packets so appliances see the original traffic. Route tables send traffic to Gateway Load Balancer endpoints, which pass it through the appliance fleet and back, making inspection transparent to both ends. It keeps flows sticky to one appliance so stateful inspection works, and it handles appliance health checks and scaling. It is a specialised tool for network security teams, not a general purpose load balancer for applications.

Classic Load Balancers

The Classic Load Balancer is the original Elastic Load Balancing product, with a mix of layer 4 and limited layer 7 features. It lacks host and path routing, target groups, HTTP/2 to targets and many integrations, and AWS has been retiring it. Teams still running Classic Load Balancers should migrate, which AWS supports with a migration wizard that creates an equivalent ALB or NLB. The migration is usually simple for HTTP services and gives access to modern features and better metrics.

Both load balancer types can also be placed behind CloudFront or Global Accelerator for global traffic. CloudFront caches and terminates HTTPS close to users and forwards misses to an ALB origin, which can then accept traffic only from CloudFront through a managed prefix list and a secret header. Global Accelerator gives two static anycast addresses that route users over the AWS backbone to the nearest healthy regional ALB or NLB, which is another way to obtain fixed addresses for an ALB and improves failover between regions. These front doors change where TLS terminates and which addresses targets see, so they belong in the design from the start.

Internet facing and internal

Each load balancer is either internet facing, with public addresses in public subnets, or internal, with private addresses reachable only inside the VPC and connected networks. Internal load balancers front services called by other services, and they are just as useful as public ones: they give a stable name, health checking and spreading across zones for internal traffic. A common layout has one internet facing ALB for public traffic and internal ALBs or NLBs for service to service traffic, each in subnets for its own tier.

Security groups apply to ALBs, and since 2023 to NLBs as well. An ALB's group decides which clients may connect, such as the whole internet for a public site or only the application tier's group for an internal service, and the target's group should then allow traffic only from the load balancer's group. NLBs created without a security group cannot gain one later, so creating every new NLB with a group, even a permissive one, keeps the option open. Targets behind an NLB without a security group must otherwise allow the client addresses directly, which is far broader.

Cost model

Both load balancers charge per hour plus per Load Balancer Capacity Unit, LCU, which measures the highest of several dimensions in each hour: new connections, active connections, processed bytes and, for ALB, rule evaluations. An ALB serving many small requests with many rules may be billed on rule evaluations, while an NLB carrying large flows is billed on bytes. For high volume services the LCU charge exceeds the hourly charge many times, so estimating it from expected traffic during design avoids surprises. Consolidating many small services behind one ALB with host based rules is often cheaper than one ALB per service.

Pick the layer you need

Use an ALB for HTTP services that benefit from request routing, WAF, authentication and request metrics. Use an NLB for non HTTP protocols, static IPs, PrivateLink, preserved client addresses or extreme connection counts, and combine them when you need both static IPs and layer 7 routing.