chapter three

3 Getting up and running with gRPC and Golang

 

This chapter covers

  • Internals of working with Protocol Buffers
  • Generating stubs from proto files
  • Adding stub generation process into CI/CD pipeline by using Github Actions
  • Maintaining proto files in a separate repository
  • Maintaining backward and forward compatibility for Protocol Buffers

The communication of two services with each other is just like two people are talking to each other. For example, those people use a telephone to connect them together just like using gRPC for inter-service communication. In same way, people use language to understand each other, just like two services use Protocol Buffers to exchange their messages. It is important to select a proper communication style to have a healthy relationship. Now that we understand how important communication strategy is, let’s see how Protocol Buffers and gRPC are used together in microservice communication.

3.1 Protocol Buffers

3.1.1 Defining Message Type

3.1.2 Protocol Buffer Encoding

3.2 Generating Stubs

3.2.1 Protocol Buffer Compiler Installation

3.2.2 Using Protocol Buffer Compiler

3.3 Maintaining Proto Files

3.3.1 Proto Project Structure

3.3.2 Automation for Source Code Generation

3.4 Backward and Forward Compatibility

3.4.1 Adding New Fields

3.4.2 Upgrading Server, But Not Client

3.4.3 Upgrading Client, But Not Server

3.4.4 Adding / Removing ‘oneof’ Fields

3.4.5 Moving Fields Out of or Into a `oneof`

3.5 Summary