Distributing requests with load balancing
Load balancing in general is a complex topic. There are many ways of implementing it. gRPC provides, by default, client-side load balancing. This is a less popular choice than look-aside or proxy load-balancing because it involves “knowing” all the servers’ addresses and having complex logic in the client, but it has the advantage of directly talking to the servers and thus enables lower-latency communication. If you want to know more about how to choose the correct load balancing for your use case, check this documentation: https://grpc.io/blog/grpc-load-balancing/.
To see the power of client-side load balancing, we will deploy three instances of our server to Kubernetes and let the client balance the load across them. I created the Docker images beforehand so that we do not have to go through all of that here. If you are interested in checking the Docker files, you can see them both in the server
and client
folders...