Skip to main content
Goal: #[micro_routes] + #[message_pattern] over gRPC with JSON wire payloads inside protobuf—aligned with nestrs_microservices::wire. Full snippets: Recipe E.

Cargo.toml

Handler + module

Listen (gRPC)

Hybrid: gRPC + HTTP

Micro CRUD patterns

Version JSON payloads (schema_version) when multiple deploys share a broker.

Production microservice RPC

Wire payload envelope (JSON inside gRPC)

Teams standardize on a small envelope inside the JSON wire body so gateways, logs, and tracing line up across services:
Handlers read payload into UserCreateReq; middleware or a shared helper copies correlation_id into tracing spans. schema_version lets you reject or branch old mobile apps without breaking the gRPC method name.

Example: user.create handler

Duplicate email surfaces as ConflictException via PrismaError mapping—callers should map 409 to “retry with different input,” not infinite retry.

End-to-end example: internal orders service

This is a realistic split many teams run in production:
  • Public HTTP API receives a checkout request.
  • Orders RPC service owns order writes.
  • Billing and inventory call into it through gRPC or a broker transport.
In production, make one service the owner of each write model. If orders are written by orders-rpc, do not also let billing-api write the orders table directly just because it shares the same database cluster.

Deploy and connectivity

Naming patterns

Use dot-separated pattern names that mirror bounded contexts: billing.invoice.issue, inventory.stock.reserve—same strings in OpenTelemetry span names and API catalogs.
Swap NestFactory::create_microservice_grpc for NestFactory::create_microservice (TCP) during local dev—the same handler impl stays valid.