5 Inter-service Communication

 

This chapter covers

  • Understanding the internals of gRPC client-server connection strategies
  • How to depend on a client module to access specific service
  • Tips and tricks for client configuration of a specific service
  • Handling errors

gRPC simply provides you to execute a server function within your local application via gRPC stubs which are responsible for marshalling request and send to server to execute it on the server side as well as unmarshalling response once the response received as shown in below.

Figure 5.1 Order Service uses Payment Service gRPC stub
Description: Diagram Description automatically generated

In the previous chapters, we already saw how to generate Go source codes from proto files, this time we will learn how to use those repositories that contains gRPC stubs as go module dependencies in client side. gRPC also provides flexible configurations for client connection to make inter-service communication more reliable. Those configurations that allow us to retry operation based on the response status or error type we get from gRPC response. Now let’s take a look physical example to better understand how communication works, and how we can handle error cases to have better failover strategy.

5.1 gRPC Service-to-Service Communication

5.1.1 Server-Side Load Balancing

5.1.2 Client-Side Load Balancing

5.2 Depending on a Module & Implementing Ports and Adapters

5.2.1 Payment Port

5.2.2 Payment Adapter

5.2.3 Implementing Payment Port

5.2.4 Implementing Payment Adapter

5.2.5 Client Configuration for Payment Stub

5.2.6 Using Payment Adapter in gRPC

5.3 Error Handling

5.3.1 Status Codes

5.3.2 Returning Error Code and Message

5.3.3 Errors With Details

5.3.4 Handling Errors on Client Side

5.4 Summary

sitemap