Load Balancing

Go gRPC load balancing #

As the load increases for gRPC services, and the services are horizontally scaled, one may notice a pattern where one instance is consuming more CPU than others.

By default, the Go gRPC client will not load balance requests. To enable load balancing with e.g. a round robin strategy, provide a default service config when initializing the connection.

const defaultServiceConfig = `{"loadBalancingConfig": [{"round_robin":{}}]}`

resolver.SetDefaultScheme("dns")

grpc.DialContext(
    ctx,
    addr,
    grpc.WithDefaultServiceConfig(defaultServiceConfig),
)