Load Balancing is the process of distributing load to different resources to make the process more efficient.
The Need for Load Balancers
Imagine a scenario where a single EC2 instance struggles to handle the traffic load from 100 users, resulting in application slowness or downtime. The solution lies in deploying multiple EC2 instances and placing a load balancer in front of them. A load balancer uses techniques like round-robin to distribute traffic evenly across the instances, ensuring optimal performance.
ALB (Application Load Balancer)
ALB operates at Layer 7 of the OSI model, making it ideal for traffic load balancing based on HTTP/HTTPS traffic attributes such as host, path, and domain. For example, if a request comes in for google.com/cricket
, ALB can redirect it to a server handling cricket-related content, while a request for google.com/football
can be redirected to a server handling football-related content. However, ALB's flexibility and feature-rich nature come at a cost, making it a bit expensive compared to NLB.
NLB (Network Load Balancer)
In contrast, NLB operates at Layer 4, making it suitable for routing TCP/UDP packets. While it lacks the ability to intercept HTTP requests and make routing decisions based on content, NLB excels in low latency and high transmission of data. It is ideal for use cases such as video streaming and game servers, where fast, efficient routing is essential.
GWLB (Gateway Load Balancer)
GWLB serves as a front-end firewall with gateway capabilities, providing high security for your applications. It is well-suited for VPN and firewall use cases, where robust security measures are required.
Auto Scaling Groups :
Auto Scaling Groups is a service that allows to automatically scale the instances(increase the number of instances) depending on the load.
Health Monitoring - ASG continuosly monitor the health of instances, when an insatnce goes down, ASG automatically creates another instances.
Auto Scaling - ASG can automatically increase the resources depending on the load.Also, we can specify the factors for which the resources to scale. We can scale the resources when specific CPU utilization or memory utilization.
Conclusion :
In conclusion, choosing the right load balancer depends on your application's specific needs. ALB is great for HTTP/HTTPS traffic routing based on content attributes, NLB excels in low latency and high data transmission, while GWLB provides enhanced security features.