0
0
AWScloud~5 mins

Network Load Balancer (NLB) in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Network Load Balancer (NLB)
O(n)
Understanding Time Complexity

We want to understand how the work done by a Network Load Balancer grows as more requests come in.

Specifically, how does the number of operations change when the number of incoming connections increases?

Scenario Under Consideration

Analyze the time complexity of handling incoming connections with a Network Load Balancer.

// Create a Network Load Balancer
aws elbv2 create-load-balancer --name my-nlb --type network --subnets subnet-123 subnet-456

// Create a target group
aws elbv2 create-target-group --name my-targets --protocol TCP --port 80 --vpc-id vpc-789

// Register targets
aws elbv2 register-targets --target-group-arn arn:aws:elasticloadbalancing:... --targets Id=i-123 Id=i-456

// Create a listener
aws elbv2 create-listener --load-balancer-arn arn:aws:elasticloadbalancing:... --protocol TCP --port 80 --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:...

// Incoming connections are routed to targets by the NLB

This sequence sets up an NLB that forwards TCP connections to registered targets.

Identify Repeating Operations

Look at what happens repeatedly as traffic flows through the NLB.

  • Primary operation: Routing each incoming TCP connection to a target instance.
  • How many times: Once per incoming connection.
How Execution Grows With Input

Each new connection causes the NLB to perform routing work.

Input Size (n)Approx. Api Calls/Operations
1010 routing operations
100100 routing operations
10001000 routing operations

Pattern observation: The number of routing operations grows directly with the number of connections.

Final Time Complexity

Time Complexity: O(n)

This means the work the NLB does grows in a straight line as more connections come in.

Common Mistake

[X] Wrong: "The NLB handles all connections instantly without extra work as connections increase."

[OK] Correct: Each connection requires routing and resource use, so more connections mean more work.

Interview Connect

Understanding how load balancers scale with traffic helps you design systems that stay reliable as they grow.

Self-Check

"What if the NLB had to perform health checks on each target for every connection? How would the time complexity change?"