gRPC
A high-performance RPC framework using Protocol Buffers for defining service contracts and generating strongly typed client and server code.
gRPC is a remote procedure call framework that uses Protocol Buffers (protobuf) to define service contracts and generate client and server code. You write a .proto file describing your services and message types, then generate strongly typed code in your language of choice.
The generated code is stricter than what you get from OpenAPI. With gRPC, you can't accidentally return data that doesn't match the schema. The compiler enforces the contract. If you change a field type in the proto definition, the code won't compile until both sides are updated. This makes gRPC a natural fit for API-First Design in service-to-service communication.
gRPC uses HTTP/2 under the hood, which gives you multiplexed streams, header compression, and bidirectional streaming out of the box. Binary serialization with protobuf is faster and more compact than JSON. For internal communication between services where you control both ends, these are significant advantages over REST.
That said, gRPC is harder to debug than JSON APIs. You can't just curl an endpoint and read the response. Browser support requires extra tooling (like gRPC-Web or a gateway). For public-facing APIs or frontend communication, HTTP/JSON with OpenAPI is usually a better choice.
In Clean Architecture, gRPC clients and servers belong in the adapters/API layer. The generated protobuf types should not leak into your domain. Map between proto messages and your domain models explicitly, the same way you would with HTTP request/response types.
For testing, component tests can call your service through its gRPC API with real infrastructure, just like they would through HTTP. The generated client makes this straightforward.
References
- Robust gRPC communication on Google Cloud Run (but not only!) — Dedicated article on building robust internal service communication using gRPC. Shows how to define proto files, generate Go servers and clients, set up authentication and TLS on Cloud Run, and explains why gRPC's strict code generation gives more confidence than OpenAPI.
- How to implement Clean Architecture in Go (Golang) — Demonstrates how gRPC clients and servers fit into Clean Architecture as adapters and ports. Shows injecting gRPC clients into application services through constructors and using port-agnostic errors that both HTTP and gRPC handlers can map.
- Microservices test architecture. Can you sleep well without end-to-end tests? — Covers testing gRPC adapter code and explains when testing gRPC clients adds value versus just duplicating implementation. Shows how component tests use gRPC-generated clients directly and how mocks replace real gRPC clients in test constructors.
- Common Anti-Patterns in Go Web Applications — Recommends generating gRPC models from Protobuf files as part of a code generation strategy. Shows how separate models for HTTP, gRPC, and database layers prevent coupling, with the application layer mapping between them.
- The Go libraries that never failed us: 22 libraries you need to know — Dedicated section on gRPC tooling. Recommends the official protoc compiler and Go plugin for generating servers and clients from .proto files. Also covers opencensus-go for adding tracing to gRPC endpoints.
- Introduction to DDD Lite: When microservices in Go are not enough — Shows refactoring gRPC handlers to use domain objects. Demonstrates how the gRPC server layer becomes a thin adapter with no domain logic after applying DDD patterns, reducing the handler to 18 lines of orchestration code.
- How to use basic CQRS in Go — Explains how CQRS command handlers can be called from any port: HTTP, gRPC, or CLI. Shows how cross-cutting concerns like logging are measured consistently whether called from HTTP or gRPC.
- Building a serverless application with Go, Google Cloud Run and Firebase — Introduces the Wild Workouts architecture with public HTTP and internal gRPC endpoints. Services expose gRPC for internal communication between trainer, trainings, and users services running on Cloud Run.
- A complete Terraform setup of a serverless application on Google Cloud Run and Firebase — Shows Terraform configuration for deploying gRPC services to Cloud Run. Covers service module definitions with protocol type, environment variable wiring for gRPC addresses, and deployment pipeline configuration for both HTTP and gRPC services.
- The Repository pattern in Go: a painless way to simplify your service logic — Shows how repository pattern and clean architecture work with gRPC handlers. Demonstrates managing transactions cleanly without coupling them to HTTP/gRPC middleware or context.
- 4 practical principles of high-quality database integration tests in Go — Notes that confidence in deployments increases when contracts between services are robust because of gRPC, Protobuf, or OpenAPI.
- Increasing Cohesion in Go with Generic Decorators — Uses gRPC as an example of multiple entry points to the same application logic. Shows how an internal gRPC API, public HTTP API, message handler, and migration can all share the same application service.
- Synchronous vs Asynchronous Architecture — Discusses gRPC and HTTP as synchronous communication patterns. Covers protobuf as a message format for both sync and async systems, noting its versioning support, binary efficiency, and cross-language code generation.
- Event-Driven Architecture: The Hard Parts — Mentions that if you already support observability features like correlation IDs for HTTP or gRPC transports, adding them for async messages shouldn't be hard.
- Is Clean Architecture Overengineering? — Explains how gRPC handlers, HTTP handlers, and message handlers all belong in the interfaces/ports layer of Clean Architecture. Each is an entry point to the application that can share the same underlying logic.
- AMA #1: Clean Architecture, Learning, Event-Driven, Go — Discusses handling timeouts in distributed systems with synchronous HTTP and gRPC communication. Explains how Go's context cancellation propagates through gRPC call chains.
- When you shouldn't use frameworks in Go — Discusses a case where a custom protobuf implementation caused issues across teams. Uses it as an example of why standard, well-maintained tools are preferable to custom framework solutions.
- DDD: A Toolbox, Not a Religion — Mentions microservices and Protocol Buffers over gRPC as part of discussing how DDD encompasses many ideas from design patterns to inter-service communication.