Skip to main content

Sync Server gRPC Dispatch Flow

The Sync Server is the fan-out point. stateset-api hands it one order; it submits that order to every downstream system the tenant has configured β€” StateSet, NetSuite, DCL, Cart.com β€” and reports per-target results. The important consequence, which shapes everything below: one call can partially succeed.

The flow

The outbox row is written in the same transaction as the order. That’s what makes dispatch at-least-once rather than best-effort: if the process dies after committing the order, the row is still there to be claimed.

Service contract

stateset.sync.v1.OrderIntegrationService, default port 50051:

SubmitOrderRequest

CreateOrderPayload carries shopify_order_id, order_number, line_items[], created_at, tags[], location_id, workflow_id, and netsuite_id. Each line item carries sku, title, quantity, price, variant_id, and shopify_line_item_id.

SubmitOrderResponse

success and a non-empty errors list are not mutually exclusive. OrderSubmissionResult carries a separate result per target β€” stateset_order_id, netsuite, dcl, cart β€” precisely because NetSuite can accept an order in the same call where DCL rejects it.Always inspect errors[] and the per-target results. Branching on success alone will silently lose a failed downstream submission.

Authentication

Credentials go in gRPC metadata, not the payload. Two schemes, tried in order: An unparseable bearer token fails UNAUTHENTICATED. Keys are matched against the tenant’s active key set, and a successful match updates that key’s last-used timestamp asynchronously.

Status codes and what they mean

The server maps its internal errors onto gRPC statuses deliberately. This mapping is the retry policy:
FAILED_PRECONDITION is the one worth special handling. It means the tenant has no configuration for that integration β€” retrying forever will never fix it, and it usually indicates onboarding was left incomplete rather than a transient fault. Alert on it instead of burying it in a retry queue.

Retrying safely

At-least-once delivery means duplicates are expected, and the fan-out makes them asymmetric.
A DEADLINE_EXCEEDED does not tell you whether downstream systems accepted the order. The call may have timed out after NetSuite created the sales order. A naive retry of the whole SubmitOrder re-submits to every target, including the ones that already succeeded.
Two things make this tractable:
  1. Retry per target, not per call. When you have partial results, use the single-target RPCs β€” CreateNetSuiteSalesOrder, CreateDclBatch, CreateCartOrder β€” to complete only what failed.
  2. Key downstream deduplication on shopify_order_id. It is stable across retries in a way that an internal ID generated per attempt is not.
Only mark the outbox row delivered when every configured target has a result. A row marked delivered on a partially-successful response is an order that is permanently half-integrated with nothing left to reconcile it.