Summary
In this chapter, we looked at the key features that we can get by using community projects such as protoc-gen-validate
or go-grpc-middleware
. We saw that we can encode request validation logic in our proto files. This makes our code less bloated and provides error message consistency across all the endpoints of our API.
Then, we looked at what middleware are and how to create one. We started with refactoring our authentication and logging interceptors. We saw that by using go-grpc-middleware
, we can focus only on the actual logic of the interceptor and have less boilerplate to deal with.
After that, we saw that we can expose tracing data from our API. We used OpenTelemetry and Prometheus to gather the data from the gRPC API and expose it through an HTTP server.
We then learned how to apply rate limiting on our APIs. This is helpful to prevent fraudulent actors or defective clients from overloading our server. We used the Token Bucket algorithm and an already existing...