Architecture: Multi-Courier Fulfillment via Shiprocket

By Engineering Team•October 2, 2026•7 min read

This is the architecture behind the decision recorded in ADR-00022 (courier aggregator vs. direct courier API) and ADR-00023 (internal mock service vs. live API for non-production calls), satisfying the requirements in BRD-010 and SR-011.

Diagram

Multi-Courier Fulfillment via Shiprocket — shipment-service's serviceability, shipment creation/fulfillment, and webhook-driven tracking flows, backed by provider-auth-service's shared OAuth2 token minting

Components

Component Language / Runtime Role
shipment-service Go Owns serviceability quoting, Shiprocket-driven shipment creation/fulfillment, and webhook-driven delivery tracking over SSE (FR-01 through FR-06).
provider-auth-service Rust Central, non-tenant-scoped OAuth2 token minter/cache for third-party providers, consumed by shipment-service via gRPC instead of each consumer logging into Shiprocket itself (FR-07 through FR-09, NFR-03).
pii-service Rust Central encrypted address-attribute store. shipment-service’s repository/pii/ resolves a billing/shipping AddressSnapshotRef into real address fields over gRPC, with tenant/user/role metadata attached, before CreateOrder runs (FR-12, NFR-07).
order-service Go Temporal checkout saga caller of ShipmentService.CreateShipment, supplying the customer-selected courier and fallback list from a prior GetServiceability call.
document-service Rust Audit-trail sink — receives one audit event per Shiprocket API call, per serviceability cache-miss, and per tracking webhook (FR-11).
mock-service Node Local stand-in for apiv2.shiprocket.in, used only in local development — see Architecture: Local Development Environment Topology for its own topology; not part of the production flows below.
Shiprocket (apiv2.shiprocket.in) External provider The aggregator’s own serviceability, order/AWB/label/invoice/pickup, and tracking-webhook APIs — the subject of ADR-00022’s decision.

End-to-end flow (A) — serviceability quoting

  1. A caller requests shipping options for an order’s items and destination pincode; shipment-service aggregates per-item weight/dimensions into a single shipment-level figure (FR-01).
  2. shipment-service checks its 1-hour serviceability cache, keyed by (tenant_id, origin_pincode, delivery_pincode, weight_group, is_cod) — a cache hit returns immediately with no call to Shiprocket or provider-auth-service (FR-01).
  3. On a cache miss, repository/providerauth/ requests a valid OAuth2 token from provider-auth-service’s GetToken, which returns a cached token or serializes a single upstream login call if none is cached or the cached one is past its safety margin (FR-07, FR-09).
  4. repository/shiprocket/’s serviceability call queries Shiprocket’s live courier-serviceability API with the authenticated token, and the result is reduced to up to two ranked tiers — STANDARD (cheapest) and EXPRESS (fastest, only when genuinely faster on a different courier) — each carrying an InternalCourierID and an ordered FallbackCourierIDs list (FR-02).
  5. The calculated tiers are written into the 1-hour cache and returned to the caller; the raw Shiprocket request/response is never persisted, only the calculated output.
  6. The cache-miss call publishes one audit event to document-service via message_publisher/documentaudit_publisher.go, fire-and-forget (FR-11).

End-to-end flow (B) — shipment creation & fulfillment

  1. At checkout, order-service’s Temporal saga calls shipment-service’s ShipmentService.CreateShipment with the customer-selected courier and its fallback list from flow (A); billing_address/shipping_address arrive as an AddressSnapshotRef{snapshot_id, type} each, never raw address fields (FR-03, FR-12).
  2. repository/pii/ resolves the shipping snapshot into real address fields via an authenticated gRPC call to pii-service’s GetAddressSnapshots, with tenant_id/user_id/role propagated as gRPC metadata; if the billing snapshot is identical to the shipping snapshot, the already-resolved shipping address is reused for billing instead of a second lookup. The decrypted address lives only in the in-memory CreateShipmentRequest for the rest of this flow (FR-12, NFR-07).
  3. shipment-service’s service layer — not any single repository method — orchestrates the five-step Shiprocket sequence in order: CreateOrder → AssignAWB → GenerateLabel → PrintInvoice → GeneratePickup, each a separate repository/shiprocket/ method with its own OAuth2 token obtained the same way as flow (A) step 3 (FR-03, NFR-01).
  4. If AssignAWB fails for the primary InternalCourierID, assignAWBWithFallback retries in order against each FallbackCourierIDs entry until one succeeds or the list is exhausted (FR-04).
  5. Each step’s outcome is persisted to shipment_shiprocket_orders for operational status, independent of the audit publish in the next step — a failed step records the failing endpoint/status code/error message, and the parent order’s status reports FAILED whenever any step fails, regardless of which one (FR-13; see TD-06 — this status has no query RPC of its own yet).
  6. Every Shiprocket API call in this sequence — on both success and failure — publishes one audit event to document-service, fire-and-forget via context.WithoutCancel(ctx) and a goroutine; a failed step publishes the raw request plus {"error": ...} as the response. The create_order event carries the now-resolved address fields as part of its raw request, masked once at persistence by document-service (FR-11, NFR-05, NFR-07; see TD-05 for a gap in that masking coverage).
  7. CreateShipment returns the Shiprocket order/shipment id, AWB code, and courier name to order-service’s saga.

End-to-end flow (C) — delivery tracking

  1. Shiprocket (or, in local development, mock-service’s webhook-simulation scheduler) posts a courier-scan event to POST /shipment/webhook/shiprocket, keyed by Shiprocket’s own order_id — the payload never carries a shipment_id (FR-05).
  2. The webhook handler records the scan into shipment_shiprocket_tracking (one document per order, scans[] holding full history newest-first) and publishes one audit event to document-service, fire-and-forget (FR-11).
  3. The same handler pushes the scan onto an in-memory, per-order broker (buffered channel, non-blocking send) (FR-06).
  4. A customer-facing client connecting to GET /shipment/api/v1/order/:id/stream first receives a catch-up event reflecting the latest known state, then falls through to the live subscription for any further scan — the stream never terminates on its own (FR-06; see Technical Debt — Multi-Courier Fulfillment Gaps, TD-01 for the broker’s single-instance limitation).