Retrying calls
As of now, we have worked only on the server side. Let us now see an important feature on the client side. This feature is the retrying of calls that failed depending on the status code. This might be interesting for use cases where the network is unreliable. If we get an Unavailable
error code, we will retry with an exponentially bigger wait time. This is because we do not want to retry too often and overload the network.
Important note
gRPC supports retries without the need for a third-party library. However, the configuration is quite verbose and not very well documented. If you are interested in trying it, you can check the following example: https://github.com/grpc/grpc-go/blob/master/examples/features/retry/README.md.
Let us get the dependency that we need (client
folder):
$ go get github.com/grpc-ecosystem/go-grpc-middleware/v2/ interceptors/retry
Then, we can define some options for the retry. We will define how many times and on which...