What is a load balancer?
You have millions of users requesting data from your app at the same time and the data needs to be delivered in a fast and reliable manner. To do this, you need more servers and an easy way to distribute traffic and requests across these servers. That’s where a load balancer comes into play.
A load balancer is the conductor orchestrating and directing traffic to the correct servers to maximize speed and utilization. If you want a formal definition, a load balancer effectively distributes incoming traffic across a group of servers. This helps your app efficiently handle more concurrent users.
Scenarios involving a load balancer:
- If a server goes down, the load balancer redirects incoming traffic to a new server
- When adding new servers, a load balancer will automatically send new traffic to the new servers you stand up
Load balancing algorithms
Your choice for a load balancer depends on your needs. Here are 3 common ones:
- Round robin – Requests are distributed across your servers sequentially.
- Least connections – A new request is sent to the server with the fewest current connections. The relative computing capacity of each server is factored into this.
- IP Hash – The IP hash of the client is used to determine which server receives the request.
Choosing the right load balancing algorithm depends on your use case. If you have international users, the IP hash might be the best route. Otherwise, the least connections might be the better alternative.
Amazon Web Service’s load balancer
With Amazon’s EC2 you only pay for what you use and it will scale up or down based on your traffic. As traffic fluctuates, servers will be taken down or added. The AWS load balancer will dynamically add or remove servers without interrupting connections.
Just another reason why I’m all about AWS.