'Where do load balancers sit in microservice architecture?

I'm planning on creating a brand new backend with microservices. I've been looking into infrastructure and I'm unsure as to where load balancers come in. Does the API gateway act as a load balancer or do they sit behind each microservice. I'd love to know.



Solution 1:[1]

You can read a really nice article about it here, but in simple words - when you have a lot of traffic to your application (i.e. your microservice), one thing you can do is to deploy your application to more than one server (even hundreds of servers), such that it's accessible in each of these servers. Now, you'd like to spread the requests to your application between the different instances such that there won't be too much load on one or other servers. Load Balancer sits between the clients of your application and the servers pool of your application, and routes the requests cleverly between the different instances, to prevent (or distribute) the load.

Solution 2:[2]

@idanz has a nice, concise answer, but if you're looking for more info on the role of an API gateway as compared to load balancers you might find this article useful. It briefly highlights the difference between an API gateway and a load balancer and shows a different approach to inter-process load balancing that improves latency:

https://www.architect.io/blog/2022-03-21/production-environment-at-different-sizes/

Disclosure: I'm the author.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 David T.