Ever built a backend service?

Sukhad Anand
2 min readApr 5, 2022

You must know about a load balancer then.

Photo by Radowan Nakif Rehan on Unsplash

1. A backend service is generally a distributed system with many servers serving the requests. So, you use a load balancer to balance out the request between different servers.

2. But, with this, a question pops to mind. Is a load balancer a single server that is distributing the requests? Doesn’t seem right, because it will become a single point of failure.

3. So, a load balancer in itself is a system with multiple nodes doing the job of load balancing. But, another question that now comes to mind is — who the hell now distributes the requests between these load balancer servers ???

4. That’s where DNS comes into play. A website abc.com is linked to multiple IP addresses which are the IPs of the load balancer servers. Now, whenever a client makes a call to the DNS, it returns a list of these IP addresses in random order. And that is how, the requests are distributed between load balancer servers, and then their job of distributing these to backend servers on the basis of certain algorithms begins.

5. There are two types of software load balancers: Layer 4 load balancer and Layer 7 load balancer. Layer 4 load balancers just have data till layer 4 of the network which is the transport layer. Layer 4 load balancers make the load balancing decisions on the basis of the IP address of the requesting server and destination servers. It does not have any information about the request parameters.

6. Layer 7 load balancers on the other hand have application layer level information too. They can make decisions on the basis of a lot of other parameters too. Modern-day load balancers are generally, layer 7 load balancers.

7. There are different algorithms that may be used for load balancers. These include Round Robin, Weighted Round Robin, Least Connection, Weighted Least Connection, Resource-Based, etc.

8 Each algorithm has its own pros and cons. You can decide the algorithm which suits you best according to your development requirements. No algorithm is the best. It totally depends on the amount of load and the type of a load of your backend service.

If you want to know in-depth about different algorithms:

https://www.youtube.com/watch?v=fOIz9uNhRFI&t=441s

--

--

Sukhad Anand

Addicted to 007 movies and music of all genres and all generations. A bit of philosophy with a pinch of music and a handful of coding.