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

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
- A caller requests shipping options for an order’s items and destination pincode;
shipment-serviceaggregates per-item weight/dimensions into a single shipment-level figure (FR-01). shipment-servicechecks 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 orprovider-auth-service(FR-01).- On a cache miss,
repository/providerauth/requests a valid OAuth2 token fromprovider-auth-service’sGetToken, 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). 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) andEXPRESS(fastest, only when genuinely faster on a different courier) — each carrying anInternalCourierIDand an orderedFallbackCourierIDslist (FR-02).- 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.
- The cache-miss call publishes one audit event to
document-serviceviamessage_publisher/documentaudit_publisher.go, fire-and-forget (FR-11).
End-to-end flow (B) — shipment creation & fulfillment
- At checkout,
order-service’s Temporal saga callsshipment-service’sShipmentService.CreateShipmentwith the customer-selected courier and its fallback list from flow (A);billing_address/shipping_addressarrive as anAddressSnapshotRef{snapshot_id, type}each, never raw address fields (FR-03, FR-12). repository/pii/resolves the shipping snapshot into real address fields via an authenticated gRPC call topii-service’sGetAddressSnapshots, withtenant_id/user_id/rolepropagated 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-memoryCreateShipmentRequestfor the rest of this flow (FR-12, NFR-07).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 separaterepository/shiprocket/method with its own OAuth2 token obtained the same way as flow (A) step 3 (FR-03, NFR-01).- If
AssignAWBfails for the primaryInternalCourierID,assignAWBWithFallbackretries in order against eachFallbackCourierIDsentry until one succeeds or the list is exhausted (FR-04). - Each step’s outcome is persisted to
shipment_shiprocket_ordersfor 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 reportsFAILEDwhenever any step fails, regardless of which one (FR-13; see TD-06 — this status has no query RPC of its own yet). - Every Shiprocket API call in this sequence — on both success and failure — publishes one audit event to
document-service, fire-and-forget viacontext.WithoutCancel(ctx)and a goroutine; a failed step publishes the raw request plus{"error": ...}as the response. Thecreate_orderevent carries the now-resolved address fields as part of its raw request, masked once at persistence bydocument-service(FR-11, NFR-05, NFR-07; see TD-05 for a gap in that masking coverage). CreateShipmentreturns the Shiprocket order/shipment id, AWB code, and courier name toorder-service’s saga.
End-to-end flow (C) — delivery tracking
- Shiprocket (or, in local development,
mock-service’s webhook-simulation scheduler) posts a courier-scan event toPOST /shipment/webhook/shiprocket, keyed by Shiprocket’s ownorder_id— the payload never carries ashipment_id(FR-05). - 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 todocument-service, fire-and-forget (FR-11). - The same handler pushes the scan onto an in-memory, per-order broker (buffered channel, non-blocking send) (FR-06).
- A customer-facing client connecting to
GET /shipment/api/v1/order/:id/streamfirst 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).
Related Documents
- BRD-010 — Nationwide Fulfillment That Scales With Order Volume
- SR-011 — Multi-Courier Fulfillment via Shiprocket: System Requirements
- ADR-00022 — Courier Aggregator vs. Direct Per-Courier API Integration
- ADR-00023 — Internal Mock Service vs. Direct Live API for Non-Production Shiprocket Calls
- Technical Debt — Multi-Courier Fulfillment Gaps
- Microservices: shipment-service, provider-auth-service, pii-service, mock-service