Microservices & Transport Standards
Priority: P0 (FOUNDATIONAL)
Microservices communication patterns and transport layer standards.
- Synchronous (RPC): Use gRPC for low-latency, internal service-to-service calls (10x faster than REST/JSON).
- Asynchronous (Events): Use RabbitMQ or Kafka for decoupling domains via fire-and-forget (
emit()).
gRPC Setup
RabbitMQ Setup
Monorepo Contracts
- Store all DTOs,
.protofiles, and Interfaces inlibs/contracts. - Services never import from sibling services — only from
contracts. - Semantic versioning of messages is mandatory. Never change a field type; add a new field.
Exception Handling
Standard HttpException is lost over RPC/TCP. Use RpcException with global filters:
Serialization
- Apply
useGlobalPipes(new ValidationPipe({ transform: true }))inMicroserviceOptionssetup, not just HTTP.
Anti-Patterns
- No cross-service imports: Services must import only from
libs/contracts, never from sibling services. - No HttpException in RPC: Use
RpcExceptionwith a globalRpcExceptionFilterfor microservice errors. - No unversioned message schema: Add new fields; never change existing field types — consumers will break.