skip to content

You are putting a public HTTPS API in front of a fleet of containers on AWS. When would you choose an Application Load Balancer (ALB) over a Network Load Balancer (NLB), and what can an ALB do that an NLB cannot?

level: middleimportance: must knowfreq 78%

answer

  1. does routing need to see the request?
  2. layer 7 proxy versus layer 4 forwarding
  3. host, path, header rules; WAF; OIDC
  4. static IP and UDP push you to NLB

basics

~20 s

Pick an ALB when the routing decision depends on the HTTP request itself - host, path, header or method - or when you want WAF, cookie stickiness or built-in OIDC login. Pick an NLB for raw TCP/UDP, static IPs and lowest latency.

solid answer

~50 s

I start from whether the routing decision needs to see the request. An ALB is a layer-7 proxy: it terminates the client connection, parses HTTP, and routes on host header, path, HTTP header, method, query string or source IP. Because it reads the request it can also do things an NLB structurally cannot - `redirect` and `fixed-response` actions, `authenticate-oidc` and `authenticate-cognito` login before the app sees traffic, an associated WAF web ACL, cookie-based stickiness, and HTTP/2 or gRPC to targets. It terminates TLS with an ACM certificate and appends the client address to `X-Forwarded-For`. An NLB works at layer 4: no header inspection, but TCP and UDP, a static IP per Availability Zone, and less added latency. For an HTTPS API in front of containers I take the ALB unless I specifically need a fixed IP, a non-HTTP protocol, or extreme connection rates.

go deeper

for a junior

Know that an ALB is the HTTP load balancer and an NLB is the TCP/UDP one, and be able to say that an ALB can send /api to one group of servers and /images to another.

for a middle

Explain that the ALB terminates the connection and parses the request, and derive the capability list from that: rule-based routing, redirect and fixed-response actions, WAF, stickiness, and X-Forwarded-For instead of a real source IP.

for a senior

Show the operational side: the 60-second default idle timeout cutting streaming responses, ELB-generated versus target-generated 5xx metrics, and knowing when to front an ALB with an NLB to get static addresses.

for a principal

Own the standard: which tier of the platform gets layer-7 features at all, whether edge auth and WAF belong on the load balancer or in the services, and what that choice costs in latency, lock-in and blast radius.

## The one distinction everything else follows from An Application Load Balancer is an HTTP proxy. It accepts the client's TCP connection, completes the TLS handshake itself, reads and parses the HTTP request, and then sends that request to a target over a separate connection that it owns and reuses. A Network Load Balancer operates at layer 4: it forwards TCP or UDP flows to a target without looking inside them. Every capability difference below is a consequence of that single fact - the ALB can act on the request because it has the request in its hands. ## What reading the request buys you **Content-based routing.** An ALB listener holds an ordered set of rules. Each rule matches on some combination of host header, URL path, an arbitrary HTTP header, the HTTP method, the query string, or the connection's source IP, and forwards to a target group. One load balancer and one DNS name can therefore front many services: `api.example.com` to one target group, `/static/*` to another. **Actions that never reach a target.** A rule can answer the request itself with a `redirect` action (the standard HTTP-to-HTTPS redirect on port 80 is exactly this) or a `fixed-response` action returning a status code and a short body - useful as a maintenance page or to cheaply reject unknown hosts. **Authentication at the edge.** The `authenticate-oidc` and `authenticate-cognito` actions make the ALB run the OIDC login flow before forwarding, so an internal tool gets single sign-on without any application code. **WAF.** An AWS WAF web ACL can be associated with an ALB, because inspecting SQL-injection patterns or rate-limiting by URI requires parsing HTTP. There is nothing to associate a web ACL with on an NLB. **Stickiness.** Cookie-based session affinity needs cookies, which means HTTP. **Modern protocols to the target.** A target group can be set to speak HTTP/1.1, HTTP/2 or gRPC to targets, so an ALB can front a gRPC service and even health-check it with a gRPC status matcher. **Per-request telemetry.** ALB access logs and CloudWatch metrics are per request: you get status codes split into `HTTPCode_ELB_5XX_Count` (the load balancer generated it) versus `HTTPCode_Target_5XX_Count` (your app did), plus target response time. An NLB can only tell you about flows and bytes. ## What you give up by choosing the ALB **The source IP.** The target's socket sees the private IP of an ALB node, not the caller. The client address arrives in the `X-Forwarded-For` request header instead, so any allow-listing, rate-limiting or geo-logic in the application has to read that header rather than the connection. **A stable address.** An ALB is reachable only by its DNS name; its underlying addresses change as it scales. If a partner's firewall needs a fixed IP to allow, an ALB alone will not give you one - that is a classic reason to reach for an NLB. **Protocol breadth.** An ALB carries HTTP, HTTPS, WebSocket upgrades and gRPC. It cannot carry SMTP, MQTT, a database wire protocol, or anything over UDP. **A hop of latency and a scaling curve.** Full termination and parsing costs a little more latency than layer-4 forwarding, and the ALB scales its own capacity in response to traffic, so an instantaneous vertical spike can outrun it. ## How I actually decide Ask three questions in order. Is the traffic HTTP? If not, the ALB is out. Does anything - routing, auth, WAF, stickiness - need to look at the request? If yes, the ALB is in. Does something outside your control need a fixed IP or the true client IP on the socket? If yes, either use an NLB or put an NLB in front of the ALB to get static addresses while keeping layer-7 features. ## Where it bites in production The ALB's idle timeout defaults to 60 seconds (`idle_timeout.timeout_seconds`, adjustable). Long-polling endpoints, server-sent events and slow report downloads get cut at exactly one minute and the team blames the application. Second, a 502 from the ALB is not the same failure as a 502 from your service - the ELB-generated code usually means the target closed the connection or returned something unparseable, so always split the two metrics before debugging. Third, remember that the scheme (internet-facing or internal) is fixed when the load balancer is created; you cannot flip a public ALB to private later.

  • What does a target actually see as the source IP of a request that came through an ALB?
    The private IP of the ALB node that proxied it, because the ALB opened its own connection to the target. The caller's address is appended to the `X-Forwarded-For` request header, so the application - and any security-group rule - must work from that header rather than the socket.
  • Can one ALB serve both a public site and an internal-only admin console?
    Not really. The scheme is chosen at creation and cannot be changed: an internet-facing ALB has public node addresses, an internal one does not. Use two load balancers, or keep the admin path on the internal ALB. Hiding it behind a path rule on a public ALB is exposure, not isolation.
  • Does an ALB support WebSocket connections?
    Yes. The ALB honours the HTTP/1.1 `Upgrade` handshake and then keeps the connection open in both directions. The catch is that the load balancer's idle timeout still applies, so a socket with no traffic is closed after the configured idle period unless the application sends periodic pings.

saying these in an interview costs you the question

  • An ALB gives you a static IP you can allow-list.
  • Only an NLB can terminate TLS; an ALB cannot.
  • Both ALB and NLB can inspect HTTP headers.
  • The target sees the real client IP as the TCP source behind an ALB.
  • You can put SMTP or a UDP protocol behind an ALB.

context