Synchronous communication best practices
This section lists some synchronous communication best practices that will help you to improve the maintainability and reliability of your synchronous communication, as well as communicate any errors to service callers clearly.
Perform excessive request validation and return correct error codes
Earlier in this chapter, we mentioned that two basic types of errors can occur during synchronous communication: client” and server error. All communication protocols, including HTTP, gRPC, and Thrift, offer support for differentiating between different error types in client and server code. For example, in our metadata server code, we used the following code to return different types of errors to our callers:
func (h *Handler) GetMetadata(ctx context.Context, req *gen.GetMetadataRequest) (*gen.GetMetadataResponse, error) {
if req == nil || req.MovieId == "" {
return nil, status.Errorf(codes.InvalidArgument, ...