skip to content

Network Load Balancer (NLB)

The layer-4 load balancer built for extreme throughput and low latency, with a static IP per AZ and the client's source IP preserved. It comes up whenever the workload is non-HTTP, needs a fixed IP for a firewall allowlist, or must hold millions of connections.

part ofAWSoverview, primer and where to startread it →
on this pageshow

questions

6

Your service must be reachable from outside its VPC. When would you put an AWS Network Load Balancer in front of it instead of an Application Load Balancer, and what do you give up by choosing NLB?

level: middleimportance: must knowfreq 78%

answer

  1. layer 4 flows versus layer 7 requests
  2. does routing need to read the request?
  3. non-HTTP protocols have only one option
  4. address versus hostname
  5. no WAF, no host or path rules

basics

~20 s

Network Load Balancer is the right choice when traffic is not HTTP, when you need a fixed IP per Availability Zone, or when you need very high connection volume at minimal added latency. You give up HTTP-aware routing, WAF and authentication actions.

solid answer

~50 s

NLB is a layer-4 load balancer: it forwards TCP, UDP and TLS flows without parsing the payload. I reach for it when the protocol is not HTTP (a game server on UDP, MQTT, a database proxy), when a partner or firewall needs a **static IP per Availability Zone** or an Elastic IP, when I need the client's source IP delivered to the target without relying on a header, or when the workload is millions of concurrent flows where the extra per-request processing of a layer-7 proxy is real cost. What I lose is everything that requires reading the request: host, path and header routing rules, redirect and fixed-response actions, OIDC authentication actions, `X-Forwarded-For` injection, and AWS WAF association, which attaches to ALB and CloudFront rather than to NLB. A common compromise is an NLB in front of an ALB — static IPs and PrivateLink at the edge, HTTP routing behind it.

go deeper

for a junior

Be ready to say plainly that ALB handles HTTP and HTTPS while NLB handles TCP, UDP and TLS, and to name one workload for each.

for a middle

Explain the mechanics behind the split: NLB forwards flows and never parses the payload, which is exactly why it supports non-HTTP protocols and offers a fixed address per subnet but no path or host routing.

for a senior

Show the production judgment: pick the type from the real constraint — partner IP allowlist, PrivateLink, protocol, connection volume — and describe the NLB-in-front-of-ALB composition and what it costs you in hops and money.

for a principal

Own the platform-wide tradeoff: a standard ingress shape everyone reuses beats per-team choices. Decide where WAF, TLS and authentication live once, and be explicit about the extra hop and dual charge that composition buys.

## Two different jobs Elastic Load Balancing is a family, not one product. The **Application Load Balancer (ALB)** operates at layer 7: it accepts an HTTP or HTTPS connection, parses each request, and decides where the request goes based on what is inside it. The **Network Load Balancer (NLB)** operates at layer 4: it sees a flow — a source address and port talking to a destination address and port — and forwards that flow to a target. It never parses a request, because at layer 4 there is no such thing as a request; there is only a connection carrying bytes. That single difference generates every practical consequence below. ## Where NLB wins **Non-HTTP protocols.** NLB listeners speak `TCP`, `UDP`, `TCP_UDP` and `TLS`. If the workload is a game server on UDP, a syslog collector, an MQTT broker, an SMTP relay or a database endpoint, ALB simply cannot front it. This is the most common reason an interview answer lands on NLB. **A stable address.** NLB provisions one IP address per enabled subnet, and you can supply your own Elastic IP for each subnet in the subnet mapping when you create the load balancer. Those addresses stay put for the life of the load balancer, which is what makes them allowlistable by a partner's firewall. ALB is addressed by DNS name only; the addresses behind that name are drawn from the AWS pool and change. **The client's source IP arrives natively.** Because NLB does not rewrite the source address for instance targets, the target's own socket reports the real client IP. A layer-7 proxy has to tell you the client address out of band, in a header. **Scale and latency profile.** NLB is designed for very high flow counts and adds very little latency, since it does no per-request work. For a service handling enormous connection volume, that is a measurable difference rather than a marketing line. **PrivateLink.** A VPC endpoint service — the provider side of AWS PrivateLink — is backed by a Network Load Balancer or a Gateway Load Balancer. If your service must be consumed privately from other VPCs or accounts, this alone can decide the load balancer type. ## What you give up Everything that requires understanding HTTP: - Listener rules that route on host, path, HTTP method, header or query string. - Redirect and fixed-response actions handled by the load balancer itself. - Built-in authentication actions that sit in front of your application. - `X-Forwarded-For` and the other forwarding headers a layer-7 proxy inserts. - AWS WAF association: WAF attaches to ALB, CloudFront and API Gateway, not to NLB. - Rich access logs. NLB access logs are produced only for TLS listeners, and describe TLS connections rather than HTTP requests, so "which URL was slow" is not a question an NLB log answers. ## The composite answer Senior answers rarely pick one. NLB targets can be an ALB, so a very common production shape is: NLB at the edge holding the Elastic IPs and the endpoint service, ALB behind it doing host and path routing, WAF on the ALB. You pay for two load balancers and add a hop, and in exchange you get static addressing and layer-7 features at the same time. ```bash # One NLB address per AZ, each pinned to an Elastic IP you already own aws elbv2 create-load-balancer \ --name payments-nlb --type network --scheme internet-facing \ --subnet-mappings \ SubnetId=subnet-0a1b2c3d,AllocationId=eipalloc-11111111 \ SubnetId=subnet-0e4f5a6b,AllocationId=eipalloc-22222222 ``` ## How to reason out loud Ask one question first: *does the routing decision need to see inside the request?* If yes, you want layer 7 and the conversation is about ALB. If no — and especially if the protocol is not HTTP at all, or the requirement is an address rather than a hostname — you want layer 4 and the conversation is about NLB. Both cost an hourly charge plus a capacity-unit charge, so cost is rarely the deciding factor; capability and addressing are.

  • If you need static IPs but also host-based routing, what would you actually build?
    Put an NLB in front of an ALB: the NLB holds the Elastic IPs (and can back a PrivateLink endpoint service), and an ALB registered as its target does the host, path and header routing, with WAF attached to the ALB. You pay for two load balancers and one extra hop. AWS Global Accelerator is the alternative when you want static anycast addresses without the second load balancer.
  • Can AWS WAF protect a workload that sits behind an NLB?
    Not on the NLB itself — WAF associates with Application Load Balancers, CloudFront distributions, API Gateway and a few other layer-7 surfaces. If the workload is HTTP and needs WAF, terminate HTTP on an ALB somewhere in the path, or put CloudFront in front. For genuinely non-HTTP traffic, your controls are network-layer ones: security groups, NACLs and AWS Shield.
  • Which load balancer type is required to publish a service through AWS PrivateLink?
    A VPC endpoint service is fronted by a Network Load Balancer or a Gateway Load Balancer; an ALB cannot back one directly. If the service is HTTP and you want ALB routing, register the ALB as a target of the NLB and expose the NLB as the endpoint service.

saying these in an interview costs you the question

  • Claims NLB can route by URL path if configured
  • Says NLB is just a cheaper ALB
  • Thinks NLB can have AWS WAF attached to it
  • Assumes ALB supports UDP or arbitrary TCP
  • Believes ALB also gives you a fixed IP address

context

open as a page

A partner will only send traffic to IP addresses on their firewall allowlist, but your endpoint currently sits behind an AWS Application Load Balancer. How does moving to a Network Load Balancer solve this, and exactly what would the partner allowlist?

level: juniorimportance: should knowfreq 52%

basics

~20 s

A Network Load Balancer gets one IP address per enabled subnet, and you can pin each to an Elastic IP you own at creation time. The partner allowlists those addresses — one per Availability Zone — instead of a DNS name.

open as a page

On an AWS Network Load Balancer, what is the difference between configuring a TLS listener and a plain TCP listener for an encrypted backend, and how do you decide between them?

level: middleimportance: should knowfreq 46%

basics

~20 s

A TLS listener makes the NLB terminate the handshake using an AWS Certificate Manager certificate and a security policy; a TCP listener passes the encrypted bytes through untouched so the target terminates. Choose termination for central certificate management, passthrough when the application must handle the handshake.

open as a page

How does client IP preservation on an AWS Network Load Balancer change what a registered target sees as the source address, and what two things does turning it on commonly break?

level: seniorimportance: should knowfreq 45%

basics

~20 s

With client IP preservation, an NLB forwards packets with the original client address intact, so targets see real client IPs rather than the load balancer's. That breaks security groups written for load balancer CIDRs, and same-VPC callers that are also registered targets.

open as a page

Your organisation must send all VPC traffic through a fleet of third-party firewall appliances that need to inspect the original, unmodified packets. Why is an AWS Gateway Load Balancer the right component here rather than a Network Load Balancer?

level: seniorimportance: nice to knowfreq 25%

basics

~20 s

Gateway Load Balancer is transparent: it is inserted as a route-table target and encapsulates the original packet in GENEVE to the appliance fleet, preserving the true source and destination. A Network Load Balancer is an endpoint clients must address directly, so it cannot sit invisibly in the path.

open as a page

A long-lived TCP connection that passes through an AWS Network Load Balancer — a pooled database session or a streaming RPC channel — dies after a few minutes of inactivity, while short request/response traffic to the same endpoint is fine. What is happening, and how do you fix it?

level: seniorimportance: nice to knowfreq 35%

basics

~20 s

The load balancer expires idle flows: an NLB drops a TCP flow with no traffic for the idle timeout, which defaults to 350 seconds. Keep the connection warm with TCP keepalives or application-level heartbeats set well below that interval.

open as a page