0
0
AWScloud~10 mins

Network Load Balancer (NLB) in AWS - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Network Load Balancer (NLB)
Client sends request
NLB receives request
NLB selects target based on flow hash
NLB forwards request to target instance
Target instance processes request and responds
NLB forwards response back to client
The Network Load Balancer receives client requests, selects a target instance using flow hashing, forwards the request, and then sends the response back to the client.
Execution Sample
AWS
resource "aws_lb" "nlb" {
  name               = "example-nlb"
  internal           = false
  load_balancer_type = "network"
  subnets            = ["subnet-12345", "subnet-67890"]
}

resource "aws_lb_target_group" "tg" {
  name     = "example-tg"
  port     = 80
  protocol = "TCP"
  vpc_id   = "vpc-abcde"
}

resource "aws_lb_listener" "listener" {
  load_balancer_arn = aws_lb.nlb.arn
  port              = 80
  protocol          = "TCP"
  default_action {
    type             = "forward"
    target_group_arn = aws_lb_target_group.tg.arn
  }
}
This code creates a Network Load Balancer, a target group, and a listener that forwards TCP traffic on port 80 to the target group.
Process Table
StepActionNLB StateTarget Group StateClient Experience
1Client sends TCP request to NLB on port 80Idle, waiting for requestTargets healthyRequest sent
2NLB receives requestProcessing requestTargets healthyRequest received by NLB
3NLB selects target using flow hashSelected target instanceTarget selectedRequest routed to target
4NLB forwards request to target instanceForwardingTarget processing requestRequest processing started
5Target instance processes and respondsWaiting for responseTarget sends responseResponse generated
6NLB forwards response back to clientIdleTargets healthyClient receives response
7Client connection closed or kept aliveIdleTargets healthyConnection ends or persists
💡 Request-response cycle completed; NLB ready for next request
Status Tracker
VariableStartAfter Step 3After Step 6Final
NLB StateIdleSelected target instanceIdleIdle
Target Group StateTargets healthyTarget selectedTargets healthyTargets healthy
Client ExperienceRequest sentRequest routed to targetClient receives responseConnection ends or persists
Key Moments - 3 Insights
How does the NLB decide which target instance to send the request to?
The NLB uses a flow hash algorithm to select a target instance, ensuring requests from the same client IP and port go to the same target. This is shown in execution_table step 3.
Why does the NLB stay 'Idle' after forwarding the response?
After completing the request-response cycle, the NLB returns to idle state waiting for new requests, as seen in execution_table step 6 and 7.
What happens if a target instance is unhealthy?
The NLB excludes unhealthy targets from selection, so requests are only forwarded to healthy targets, keeping client experience smooth. This is implied in variable_tracker where targets remain healthy.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the NLB select the target instance?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Check the 'Action' column in execution_table row for step 3 where target selection happens.
According to variable_tracker, what is the NLB state after step 6?
AProcessing request
BSelected target instance
CIdle
DForwarding
💡 Hint
Look at the 'NLB State' row under 'After Step 6' in variable_tracker.
If a target becomes unhealthy, how would the client experience change in the execution_table?
AClient receives response slower or errors
BNLB state changes to 'Error'
CTarget group state shows 'Targets healthy'
DClient request is dropped immediately
💡 Hint
Consider how unhealthy targets affect response time and client experience in execution_table.
Concept Snapshot
Network Load Balancer (NLB) forwards TCP/UDP traffic at connection level.
Uses flow hash to select healthy targets.
Handles millions of requests with low latency.
Supports static IP and preserves client IP.
Ideal for extreme performance and scaling.
Full Transcript
A Network Load Balancer (NLB) receives client requests on a TCP port. It uses a flow hash algorithm to select a healthy target instance from its target group. The NLB forwards the request to the selected target, which processes it and sends back a response. The NLB then forwards the response to the client. After completing the request-response cycle, the NLB returns to idle state, ready for new requests. Unhealthy targets are excluded from selection to maintain smooth client experience.