Skip to main content

gRPC

StateSet exposes 17 gRPC services alongside the REST API, covering the same commerce domains. Reach for gRPC when you’re calling service-to-service and want a typed contract and lower per-call overhead than JSON over HTTP.
gRPC is not a drop-in mirror of REST. Two differences will bite you if you assume otherwise:
  • Pagination is page-based (page, per_page), not cursor-based like the REST endpoints.
  • Money is an integer in minor unitsMoney { currency: "USD", amount: 1099 } is 10.99,not10.99, not 1,099.
Both are covered below.

Connecting

The gRPC server listens on its own port — by default the HTTP port plus one, overridable with grpc_port.
Gzip compression is enabled in both directions on every service, so a client that negotiates gzip gets it for free.
Set the HTTP/2 keepalive interval if your clients sit behind a load balancer that reaps idle connections. Without it, a long-lived channel can be silently dropped and the next call fails rather than reconnecting cleanly.
Every request is assigned an x-request-id if it doesn’t carry one, and that ID is propagated to the response — the same correlation identifier the REST API uses. Log it.

The shared vocabulary

Four messages in stateset.common are used across every service. Get these right once.
Money.amount is an int64 in the currency’s smallest unit. Sending 10.99 is not possible — the field is an integer — and sending 1099 while thinking in dollars overcharges by 100×. Convert at the boundary and assert on the result.
PaginationRequest.page is 1-based. Page 0 is not the first page.

Services

Note the package name for returns: stateset.return_order, not stateset.returnreturn is a reserved word in several target languages, so the package is qualified. Generated client namespaces follow suit.

A service in full

ReturnService is representative — a create, a get, a status transition, and a filtered list:
The filter fields on a List request are AND-ed, and an empty string means “don’t filter on this” rather than “match empty”.

Calling a service

Errors

Failures come back as gRPC statuses rather than the REST error envelope. The mapping to expect:
A DEADLINE_EXCEEDED on a write does not tell you whether the write happened — the server may have committed and then failed to respond within the deadline. Treat writes as at-least-once and make them idempotent on your side, keyed on your own identifier.