Search code examples
kubernetesrpcgrpc

Does a gRPC and Kubernetes connection only dial to one replica?


I have been studying gRPC and Kubernetes with Go. In my golang code, my API Gateway dials my micro services in a init() function before main begins. My Question is if I have multiple replicas of my micro services and my API Gateway dials a one-time connection to the micro service does it stay connected to the first pod/replica that the load-balancer sends that traffic to? If not how does a load balancer keep that dialed connection active? Thank You


Solution

  • If you use a load balancer in gRPC-Go, the load balancer tells gRPC which backends it should stay connected to, and for each request, which one to use. For example, the RoundRobin balancer will attempt to stay connected to every backend returned by the resolver, and rotate through all of the ones that were successfully connected.

    This doc covers the high-level basics of load balancing in gRPC if you would like more information.