Blog

Blog

All you Need to Know about Amazon’s Network Load Balancer

Amazon’s Network Load Balancer

Amazon’s Network Load Balancer

Amazon’s Network Load Balancer (NLB) is a highly scalable and performant load-balancing service that distributes incoming network traffic across multiple backend targets, such as EC2 instances, containers, and IP addresses. In this blog, we will explore the key features and benefits of Amazon’s Network Load Balancer, along with some code examples.

image

What is a Network Load Balancer?

A Network Load Balancer (NLB) is a load balancing service provided by Amazon Web Services (AWS) that distribute incoming network traffic across multiple targets, such as EC2 instances, containers, IP addresses, and Lambda functions, within one or more subnets of a Virtual Private Cloud (VPC). It operates at the Transport layer (Layer 4) of the OSI model, meaning it can balance both TCP and UDP traffic, and it provides high throughput, low latency, and high availability for applications that require extreme performance and scalability.

Choosing the Right Load Balancer:

Choosing the right load balancer for your application depends on your specific requirements, such as the type of traffic, the level of scalability and availability needed, the level of security, and the cost. AWS provides three types of Elastic Load Balancers (ELB): Application Load Balancer (ALB), Network Load Balancer (NLB), and Classic Load Balancer (CLB).

image

Types of Elastic Load Balancers:

  1. Application Load Balancer (ALB): operates at the Application layer (Layer 7) of the OSI model and is best suited for HTTP/HTTPS traffic. It can route traffic based on content-based routing, host-based routing, path-based routing, and support WebSockets.
  2. Network Load Balancer (NLB): operates at the Transport layer (Layer 4) of the OSI model and is best suited for TCP/UDP traffic. It can handle millions of requests per second with low latencies and is ideal for high-performance applications.
  3. Classic Load Balancer (CLB): operates at both the Application and Transport layers of the OSI model and is ideal for applications that use HTTP/HTTPS, TCP, or SSL protocols. It provides basic load-balancing functionalities and is the oldest type of load balancer provided by AWS.

Does Network Load Balancer cost more?

The cost of using an NLB depends on the amount of data processed by the load balancer and the number of active connections per hour. NLB pricing is based on a per-hour rate, with additional charges for data processed and active connections. While NLB may have a higher cost than the other types of load balancers, it provides high throughput, low latency, and high availability, making it a cost-effective solution for applications that require extreme performance and scalability.

Key Features and Benefits of Amazon’s Network Load Balancer:

  1. High performance and low latency: Amazon’s Network Load Balancer is designed to handle high volumes of traffic with low latency. It uses a stateful network protocol to maintain persistent connections between clients and targets, which helps to reduce connection setup time and improve application performance.
  2. Intelligent traffic distribution: Amazon’s Network Load Balancer distributes traffic intelligently across multiple backend targets based on the protocol, port, and IP address. It supports multiple protocols, including TCP, UDP, and TLS, and allows you to configure traffic routing rules based on source IP, destination IP, and port.
  3. Scalability: Amazon’s Network Load Balancer is highly scalable and can handle millions of requests per second. It can automatically scale up or down based on the traffic volume, without any disruption to your applications.
  4. High availability: Amazon’s Network Load Balancer is designed to provide high availability and fault tolerance. It automatically detects and routes traffic to healthy targets, and can handle failures in the backend targets or availability zones.
  5. Security: Amazon’s Network Load Balancer supports SSL/TLS encryption and provides protection against common network attacks such as SYN floods, IP spoofing, and port scanning.
image

Code Examples:

Here are some code examples to help you get started with Amazon’s Network Load Balancer:

Creating a Network Load Balancer:

To create a Network Load Balancer, you can use the AWS Management Console, AWS CLI, or AWS SDKs. Here’s an example using the AWS CLI:

aws elbv2 create-load-balancer --name my-nlb --type network \
--subnets subnet-12345 subnet-67890 --scheme internal \
--tags Key=Name,Value=my-nlb

This command creates a Network Load Balancer with the name “my-nlb”, type “network”, and two subnets in the internal scheme.

Registering Targets:

After creating a Network Load Balancer, you need to register backend targets to receive traffic from the load balancer. Here’s an example using the AWS CLI:

aws elbv2 register-targets --target-group-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 --targets Id=i-1234567890abcdef0 Id=i-0abcdef123456789

This command registers two EC2 instances with IDs “i-1234567890abcdef0” and “i-0abcdef123456789” to the target group with ARN “arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067”.

Configuring Listener Rules:

After registering targets, you need to configure listener rules to route incoming traffic to the appropriate backend targets. Here’s an example using the AWS CLI:

aws elbv2 create-listener --load-balancer-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/net/my-nlb/74e86a9f8c522f66 --protocol TCP --port 80 --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-target

This command creates a TCP listener on port 80 for the Network Load Balancer with ARN “arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/net/my-nlb/74e86a9f8c522f66” and forwards the traffic to the target group with ARN “arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067”.

Configuring Health Checks:

To ensure that the backend targets are healthy and available to receive traffic, you can configure health checks for the target group. Here’s an example using the AWS CLI:

aws elbv2 configure-health-check --health-check-protocol TCP --health-check-port 80 --health-check-path /health \
--health-check-interval-seconds 30 --health-check-timeout-seconds 5 --healthy-threshold-count 2 --unhealthy-threshold-count 2 \
--target-group-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067
image

This command configures a TCP health check on port 80 with the path “/health” for the target group with ARN “arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067”. The health check interval is set to 30 seconds, the timeout is set to 5 seconds, and the healthy and unhealthy threshold counts are both set to 2.

Conclusion:

Amazon’s Network Load Balancer is a highly scalable and performant load-balancing service that can distribute incoming network traffic across multiple backend targets with low latency and high availability. With intelligent traffic distribution, scalability, security, and easy-to-use APIs, Amazon’s Network Load Balancer is a powerful tool for building and managing modern applications on AWS.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare

Subscribe to Newsletter

Stay ahead of the rapidly evolving world of technology with our news letters. Subscribe now!