SR-011 — Multi-Courier Fulfillment via Shiprocket: System Requirements

By Engineering Team•October 2, 2026•6 min read
Metadata Details
System Name shipment-service + provider-auth-service — Multi-Courier Fulfillment
Document ID SR-2026-FUL-001
Author Engineering Team
Status Approved

Traces back to BRD-010 — Nationwide Fulfillment That Scales With Order Volume.


Functional Requirements

Serviceability & Rate Quoting

  • FR-01 (Cached Serviceability Lookup): GetServiceability MUST return the available delivery tiers (STANDARD/EXPRESS) for a given destination pincode, caching each pincode’s result for up to 1 hour so a repeat quote for the same pincode does not require a live call to Shiprocket.
  • FR-02 (Primary + Fallback Courier Selection): each serviceability result MUST carry an InternalCourierID plus an ordered FallbackCourierIDs list, so a later shipment-creation step can retry against an alternate courier without performing a second serviceability lookup.

Shipment Creation & Fulfillment

  • FR-03 (Multi-Step Fulfillment Orchestration): CreateShipment MUST execute, in order, CreateOrder → AssignAWB → GenerateLabel → PrintInvoice → GeneratePickup, with the sequencing owned by the service layer — never hidden inside a single repository call that internally performs more than one Shiprocket API call (per the layered architecture standard’s one-method-per-endpoint rule).
  • FR-04 (Automatic Courier Fallback on AWB Assignment): if AssignAWB fails for the InternalCourierID, the service MUST retry in order against each entry in FallbackCourierIDs before failing the shipment-creation request.
  • FR-05 (Delivery Tracking via Webhook): shipment-service MUST expose a webhook receiver accepting Shiprocket’s delivery-status callbacks, keyed by Shiprocket’s own order_id — the real callback payload never sends a shipment_id, so the receiver MUST NOT depend on one.
  • FR-06 (Catch-Up + Real-Time Status Stream): shipment-service MUST expose a per-order streaming endpoint that delivers both the status history already recorded for that order (catch-up on connect) and any further status change as it arrives (always-subscribe), without requiring the client to poll.
  • FR-12 (Secure Address-Snapshot Resolution): CreateShipment MUST resolve a billing/shipping AddressSnapshotRef into real address fields by calling the central encrypted PII store over gRPC with tenant_id/user_id/role metadata attached, never by accepting raw address fields directly in the request; when the billing snapshot is identical to the shipping snapshot, the service MUST reuse the already-resolved shipping address for billing rather than issuing a second lookup.
  • FR-13 (Per-Step Fulfillment Status Tracking): each of CreateShipment’s five Shiprocket API steps (CreateOrder, AssignAWB, GenerateLabel, PrintInvoice, GeneratePickup) MUST record its own outcome — success or failure — into shipment-service’s own operational-status record, independent of the audit-trail publish (FR-11); a failed step MUST capture the failing endpoint, HTTP status code, and error message as structured fields rather than only being logged, and the order’s overall status MUST report FAILED whenever any step fails, regardless of which step, without regressing a later successful milestone back to an earlier one. (Gap — this status record has no gRPC/REST surface exposing it to any caller; recovering it today means a direct MongoDB query. Tracked as technical debt — see Technical Debt — Multi-Courier Fulfillment Gaps, TD-06.)

Provider Authentication

  • FR-07 (Centralized Token Minting): any outbound call to a third-party provider’s API MUST use a short-lived OAuth2 access token obtained from a central token service — no calling service MUST mint or independently cache its own copy of a provider credential.
  • FR-08 (Per-Provider Strategy): the central token service MUST support onboarding a new third-party provider by adding one new strategy implementation, without changing the logic already written for a provider already integrated.
  • FR-09 (Cache-Miss Serialization): a token-cache miss for a given provider MUST serialize concurrent refresh attempts so that only one upstream login call is made per expiry, with other concurrent callers waiting on and reusing its result rather than each independently calling the provider’s login endpoint.

Local Development

  • FR-10 (Local Provider Mock): a local mock of the third-party provider’s API MUST be available so serviceability, shipment-creation, and tracking flows can be developed and tested without calling the real provider, including the ability to simulate a specific failure scenario on a per-request basis — satisfied by mock-service.

Audit Trail

  • FR-11 (Fulfillment Audit Publishing): every call to the third-party provider’s API, every serviceability cache-miss lookup, and every inbound tracking webhook MUST publish an audit event carrying the request/response payload, per the audit trail standard’s envelope shape.

Non-Functional Requirements

Composition & Reuse

  • NFR-01 (Per-Endpoint Repository Split): each third-party provider API endpoint MUST be wrapped by its own repository method — never one aggregate method that internally sequences multiple calls — per the layered architecture standard’s external API integration doctrine.

Configuration

  • NFR-02 (Fail-Fast Required Configuration): the pickup-location identifier and any per-endpoint base-URL override needed for local/mock routing MUST be validated at service boot, not discovered missing on first request. (Gap — the pickup-location identifier is a single fixed value, which assumes one warehouse. Tracked as technical debt — see Technical Debt — Multi-Courier Fulfillment Gaps, TD-03.)

Multi-Tenancy

  • NFR-03 (Non-Tenant-Scoped Shared Credentials): the central token service’s provider configuration and cached tokens MUST NOT be tenant-scoped, since the same provider credentials are shared across every tenant regardless of which tenant’s order triggered the call.

Reliability

  • NFR-04 (Streaming Broker Limitation): the per-order status-stream broker runs in-memory, single-instance, with no replay of missed events on scale-out. (Gap — a client connecting to a different instance than the one that received a status update will miss it. Tracked as technical debt — see Technical Debt — Multi-Courier Fulfillment Gaps, TD-01.)
  • NFR-05 (Fire-and-Forget Audit Publishing): an audit-publish failure MUST be logged but MUST NEVER fail or block the RPC/webhook response that triggered it, consistent with the audit trail standard’s established pattern and Go’s context.WithoutCancel convention (see the platform’s observability & tracing standards).
  • NFR-08 (Idempotent Status Persistence Under Retry): the per-step status write backing FR-13 MUST be idempotent under a retried CreateShipment orchestration — keyed by (tenant_id, order_id) — so a Temporal activity retry re-executing an already-attempted step overwrites rather than duplicates its own prior recorded outcome.

Operational Workflow Coverage

  • NFR-06 (Delivery-Exception Handling — Known Limitation): a failed or non-deliverable shipment SHOULD be detected and routed into a defined remediation workflow rather than surfacing only as a terminal webhook status with no further automation. (Gap — no automated non-delivery workflow exists today. Tracked as technical debt — see Technical Debt — Multi-Courier Fulfillment Gaps, TD-02.)

PII Handling

  • NFR-07 (No PII At Rest In Shipment-Service, Masked In The Audit Trail): a resolved address’s decrypted fields MUST NOT be persisted into any of shipment-service’s own collections — they MUST exist only in memory for the duration of the request that needs them — and MUST reach document-service’s audit sink only in its established masked-at-persistence form, per the audit trail standard. (Gap — document-service’s mask-key list does not yet cover every field this resolved address introduces to the audit trail. Tracked as technical debt — see Technical Debt — Multi-Courier Fulfillment Gaps, TD-05.)