5 Interservice communication

 

This chapter covers

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

In the previous chapter, we implemented a gRPC service for the Order service. In this chapter, we will implement a gRPC client for that service to show how underlying communication works in microservice architecture. You can see the high-level picture of interservice communication in figure 5.1.

Figure 5.1 The Order service uses a Payment service gRPC stub.

In previous chapters, we saw how to generate Go source codes from proto files; now, we will learn how to use repositories that contain gRPC stubs as Go module dependencies on the client side. gRPC also provides flexible configurations for client connections to make interservice communication more reliable. These configurations allow us to retry operations based on the response status or error type we get from the gRPC response. Let’s look at an example to better understand how communication works and how we can handle error cases to have a 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 and implementing ports and adapters

5.2.1 Payment port

5.2.2 Payment adapter

5.2.3 Implementing the payment port

5.2.4 Implementing the payment adapter

5.2.5 Client configuration for a payment stub

5.2.6 Using a payment adapter in gRPC

5.3 Error handling

5.3.1 Status codes

5.3.2 Returning an error code and message

5.3.3 Errors with details

sitemap