Best Tips to Get Most out of AWS Load Balancer
AWS ELB (Elastic load balancer) automatically distributes incoming application traffic across multiple targets and virtual appliances in one or more Availability Zones (AZs). That helps you achieve high availability and fault tolerance. In this article, we will share with you some tips that will help you best utilize AWS load balancer. We will also provide insights on the best use cases of ALB and NLB, which are the two most commonly used load balancers.
Morgan PerryApril 28, 2022 · 5 min read
AWS provides three types of load balancers:
- Application load balancer
- Network load balancer
- Gateway load balancer
In this article, we will share with you some tips that will help you best utilize AWS load balancer. We will also provide insights on the best use cases of ALB and NLB, which are the two most commonly used load balancers.
Network load balancer (NLB) operates on layer 4 only and can handle both TCP and UDP and TCP connections encrypted with TLS.
On the other hand, Application Load Balancer (ALB) works at layer 7 (HTTP) and is usually used for web-based traffic and web servers.
Gateway Load Balancer is used for your third-party virtual applications. Find below some factors that will help you decide if you should go for Application Load Balancer, Network Load Balancer, or Gateway Load Balancer.
- For web servers, you should use ALB, which operates on the application layer. You can redirect traffic based on web requests and apply routing based on the incoming HTTP request.
- NLB, on the other hand, is not aware of the application context, so it is not capable of routing based on the HTTP request contents
- Choose NLB if you expect raw traffic load and network spikes. Using NLB, you can examine the TCP packets but not the HTTP request.
- Choose NLB if your main goal is to reduce network lag and increase ingress-egress throughput while properly routing high traffic. RDP, SSH are some example applications suitable for NLB
- Choose NLB if you expect the traffic load to be millions per second. ALB might not be the best choice in this case
- Choose Gateway load balancer if you want to use load balancing for your third-party virtual appliances. For applications hosted on standard AWS components/services, ALB or NLB is a better option.
- Enforce traffic redirect from HTTP to HTTPS. You can set up a rule which will force all HTTP traffic to HTTPS
- Make sure that NLB listeners are on secure protocol like TLS. Prefer TLS 1.3 instead of TLS 1.2. In the case of ALB, ensure HTTPS listener.
- You should prefer SSL termination on ALB instead of your instances. It will offload the SSL processing to Amazon, saving both time and cost.
- Most load balancers are on a public subnet, so make sure to configure security groups for your ELB properly. Make sure your security groups open only specific ports and protocols.
- Prefer to use the SSL certificate generated through Amazon Certificate Manager. It will take you less than a minute to configure it for the load balancer, and it will save your costs too.
- Make sure you register your EC2 instances in different availability zones. This will ensure high availability.
- Ensure to enable ELB deletion protection. This will help you with the accidental deletion of your load balancer.
- Try to set up at least 2 healthy targets with each ELB to bring you closer to the high availability needs.
- Enable cross-zone load balancing so that each load balancer node distributes traffic across the registered targets in all enabled Availability Zones
- AWS load balancers scale best with a gradual increase in traffic load. They do not respond well to spiky loads and can break if they receive too much flash traffic. The best way to handle this is to pre-warm your load balancer by contacting AWS support.
- When configuring your application’s domain, always make it a point to the ELB’s DNS instead of the IP.
- If you are using a containerized application, then it is best to use ECS with ALB. You can utilize the feature of dynamic port mapping to run multiple tasks from a single service on the same container instance.
- With ECS, you can associate multiple target groups per ECS service. This allows you to maintain a single ECS service that can serve traffic from both internal and external load balancers and support multiple path-based routing rules and applications that need to expose more than one port.
- Make sure you are using the right threshold for health checks. You don’t want your EC2 instances to be considered healthy/unhealthy too late or too early.
- Lambda is a perfect choice for a target type if you are aiming for serverless application architecture.
- Enable connection draining. If a back-end instance fails to keep up with the recommended health checks, the load balancer will not send any new requests to the unhealthy instance. At the same time, it will still allow existing requests to complete
- Remember, the cost of ELB varies from region to region. You can take advantage of first-year free credits to save costs. Also, delete the unused ELB otherwise, it might add to your bill
- Note that AWS load balancers cannot operate between regions. For this, you will need to use the AWS route 53 service.
- Use monitoring tools to keep an eye on the critical metrics associated with the load balancer. Critical metrics include the number of healthy hosts, latency, number of requests, error rates, etc.
- You can use Amazon CloudWatch for monitoring ELB. Using DataDog is another option for detailed monitoring of your load balancers.
- You can reduce costs by using multiple target groups and multiple certificates. Using SNI feature, you can host multiple TLS secured applications, each with its own TLS certificate, behind a single load balancer.
Scalability is an inevitable need of every growing business. AWS elastic load balancers (ELB) are a must-have if you want to achieve horizontal scaling in your application. Many new entrants to AWS are unable to use the ELB efficiently because they do not have the required expertise. While the above tips will help you use the AWS load balancer smartly and get maximum utilization, it will remain complex and challenging to manage over time, especially if you use microservices or your application is containerized. A modern solution like Qovery will help you encapsulate the complexities associated with the above tasks. You can achieve the same goals with simplicity and without spending too much time configuring the above tasks. Try Qovery out for free!