Load balancing is a feature that helps evenly distribute network traffic and requests to different targets. Since it is a feature, it operates at the logic layer, and can be provided by a server or even as a separate feature managed by a dedicated device, known as a load balancer.
On AWS, there are three types of load balancers. These types have different components, mostly similar (but still different) targets, and most importantly, the criteria for packet forwarding also differ. They are:
The load balancer gathers information about the targets within the same group, allowing it to forward packets to one of the different targets in a group.
In this case, the target of the NLB will be the EC2 server. We will use the NLB to connect to the API Gateway through a VPC Link.
The load balancer needs to know whether the targets it forwards packets to are still operational. The load balancer sends a request to the target server or directly to the server (if the server is the target). If the load balancer does not receive a response, it will remove or “forget” that target to avoid forwarding packets to it.
In this workshop, we will use a Network Load Balancer (NLB) placed in the Private VPC. It will act as an intermediary, forwarding user requests (packets) from the API Gateway to the web server inside the Private VPC.
The Network Load Balancer doesn’t pay attention to the protocol or request details of the packet. It only focuses on the destination address in the packet. As a result, targets in the NLB receive packets slightly faster compared to ALB. In this workshop, the target is a single EC2 instance. However, in reality, when the application has more users, a single EC2 instance won’t be able to handle a large number of user requests.
Therefore, we have two solutions:
In this setup, the NLB will evenly distribute packets to each instance in the group.