protoc is the Protocol Buffers compiler. It turns .proto message and service definitions into language-specific code for gRPC clients and servers. In an order-creation flow, generated Payment stubs let the Order service call Payment without writing the client interface or data-exchange code by hand; each service still implements its own business logic. section 2.5.1 section 3.2
To generate Go code:
- Define request and response messages and an RPC service in a .proto file. Set go_package for the generated package. section 3.2.2
- Install protoc, then install protoc-gen-go and protoc-gen-go-grpc with go install. section 3.2.1
- Run protoc with Go message and gRPC output options. Use -I when imported .proto files need a search path; paths=source_relative preserves the input-relative folder structure. section 3.2.2
Listing 2.1 Command to generate source code for Go
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
payment.proto
The Payment command generates Go message code and gRPC code beside payment.proto using source-relative paths. section 2.5.2
For proto/order.proto, generation produces order.pb.go for message operations and order_grpc.pb.go for gRPC functionality. The latter exposes the generated NewOrderClient constructor and OrderClient interface. Import the generated package, create a client and call Create; implement the server-side behavior separately. section 3.2.2 section 3.2
Order calls Payment
The Order service dials Payment, passes the connection to pb.NewPaymentClient, then calls payment.Create(ctx, request). The generated method accepts a context even though the .proto RPC declaration does not specify one. A timeout can cancel a call that receives no response; the caller must still handle errors and decide when to retry. section 2.5.3
Generated code can stay with a service or be published from a separate schema repository. A GitHub Actions workflow can run protoc for Order, Payment and Shipping when a version tag is pushed, initialize Go modules and publish generated artifacts for consumers. Keep schema changes backward and forward compatible to avoid service disruption or data loss. section 3.3.2 section 3.5



