A load balancer takes incoming internet traffic and distributes it across multiple servers, making sure none of the servers get overloaded and everything runs efficiently. If one server goes down, the load balancer sends traffic to the remaining healthy servers.
Algorithms
Here are some common load balancing algorithms:
1. Round Robin
Distributes requests sequentially across the available servers in a circular order. The traffic is evenly spread across all servers, preventing one server from getting too many users at once.
Pro: Simple to implement and ensures every server gets some traffic.
Con: Doesn’t consider server load, so busy servers might still get more traffic.
2. Weighted Round Robin
Similar to Round Robin, but assigns a weight to each server. Servers with higher weights receive more requests.
Pro: Servers with more capacity get more traffic, balancing the load better.
Con: Requires knowing each server’s capacity, which may not always be accurate or easy.
3. IP Hash
Uses the client’s IP address to determine which server will handle the request. The same client will always be directed to the same server unless it goes down.
Pro: Ensures the same user (IP) always connects to the same server, good for session consistency.
Con: If one server goes down, it might cause problems for users assigned to that server.
4. Least Connections
Directs traffic to the server with the fewest active connections.
Pro: Sends traffic to the server with the fewest active connections, helping avoid overloads.
Con: Doesn’t account for the amount of work each connection requires, so it might still overload servers.
5. Least Response Time
Directs traffic to the server with the fewest active connections and the fastest response time.
Pro: Directs traffic to the server responding the fastest, improving user experience.
Con: Requires constant monitoring of server response times, which adds complexity.
6. Resource-based
A resource-based load balancing algorithm takes into account the current load or capacity of each server before deciding where to send new requests.
Pro: Optimizes performance by checking how busy each server is before assigning traffic.
Con: More complex to set up and requires monitoring server resource usage continuously.
Books I am Reading
I am reading a graphic novel Black Hole by Charles Burns, the story kind of strange and creepy, but very beautiful art, loving it so far. It’s a horror genre where the story is about some teenagers who are plagued by a sexually transmitted disease.
I am also reading How to Fail at Almost Everything and Still Win Big by Scott Adams, who is the creator of Dilbert comic strip. I would say the book is part autobiogrpahical part self-help, he talks about his own failures, his struggles and how he views success.
A system is something you do on a regular basis that increases your odds of happiness in the long run. If you do something every day, it’s a system. If you’re waiting to achieve it someday in the future, it’s a goal. - Scott Adams
Cool read!