Network Load Balancer
Learn how to distribute incoming TCP and UDP traffic across multiple targets using Network Load Balancer.
Network Load Balancer (NLB) operates on the transport layer, the fourth layer of the OSI model, and is used to distribute incoming TCP and UDP traffic across multiple targets. NLB uses a single static IP address and is optimized to handle sudden and volatile traffic patterns.
Once a Network Load Balancer receives a request from a client, it tries to open a connection with a target from the target group on the port specified in the targets’ listener rule. The protocols Network Load Balancers support are TCP, TLS, UDP, and TCP_UDP. NLB supports zonal isolation, which means it was created for architectures residing in a single AZ. However, using multiple zones is recommended as it increases the availability of our applications.
Internet vs. internal facing load balancers
We can create internet and internal facing Network Load Balancers in the AWS Cloud. The internet-facing NLBs are used to route the traffic coming from the public internet to the backend AWS resources such as EC2 instances or other web and application servers. While creating an internet-facing load balancer, we can specify an Elastic IP address that provides us with static IP addresses that will not change during the life of the load balancer.
Internal-facing load balancers are created to route client requests within a private network or a VPC (virtual private cloud) to access resources that are not accessible directly from the public internet. These types of load balancers don't have a public IP address and are accessed through a private static IP address, which does not change during the life of a load balancer. Once a load balancer is created, we can not change its IP address.
Target groups in NLB
Targets of a Network Load Balancer are registered in a target group, which is then used to route requests. When a
Network Load Balancers support EC2 instances, private IP addresses, and Application Load Balancers as their targets. We can use on-premises servers as targets if the selected target type is IP by connecting them to the AWS cloud using AWS Direct Connect or AWS Site-to-Site VPN.
Using ALB as a target
Network Load Balancers can forward the requests it receives to an Application Load Balancer. Following are some use cases where ALBs are added as targets for NLBs:
Multimedia services: A combination of NLB and ALB can be used in multimedia services where a single endpoint is required for multiple protocols, such as HTTP for signaling and RTP to stream content.
AWS PrivateLink: An NLB can be used to create a route between clients and an ALB over AWS PrivateLink.
Security groups for NLBs
Security groups are virtual firewalls that control the incoming and outgoing traffic for AWS resources. In a Network Load Balancer, it is optional to add a security group. However, it is recommended to add a security group to your load balancer and specify the ports and IP addresses that can access our load balancers. If we don’t associate a security group with our NLB, all client traffic can reach the load balancer listeners, and all traffic can leave the load balancer.
Main features of NLB
Following are some of the main features of an NLB that distinguish it from an ALB:
Client IP preservation: By default, the IP address of a client is replaced with the IP address of the load balancer before the request is forwarded to a target. However, Network Load Balancers have a client IP preservation feature. This means the IP address of the client who made the connection request is preserved and can be forwarded to the target. This feature is useful in applications where we need to process the IP address of the client. For example, the IP address of the client can be used to monitor and analyze the pattern of the requests received.
Health checks: We can only use TCP, HTTP, or HTTPS protocols to create health checks for the target groups associated with our NLBs.
Low latency: NLBs can be used in applications that require low latency.
Get hands-on with 1300+ tech skills courses.