ADR-00023 — Internal Mock Service vs. Direct Live API for Non-Production Shiprocket Calls

By Engineering Team•October 2, 2026•6 min read
  • Status: Approved / Implemented
  • Date: 2026-10-02
  • Authors: Engineering Team

Context

Shiprocket does not provide a dedicated, isolated sandbox environment for free end-to-end integration testing — every call is made against a live account. Within that live API, cost and side effects are not uniform across endpoints:

  • Serviceability/rate quoting (courier/serviceability) and authentication (auth/login) are read-only and carry no wallet cost — safe to call repeatedly against the live API.
  • Order creation, AWB assignment, label generation, invoice printing, and pickup scheduling are state-mutating: they deduct real wallet balance and, past AWB assignment, trigger real courier-side pickup activity.

Running local development, pull-request CI, and routine QA cycles directly against the live API for the state-mutating group would mean every test run deducts real wallet balance, every test run creates a phantom order a courier may act on, and every test run depends on live network availability and Shiprocket’s own rate limits — none of which is acceptable for a pipeline that needs to run frequently, deterministically, and without a human watching a wallet balance.

ADR-00022 already decided to integrate with Shiprocket as the aggregator; this decision is about how that integration is exercised before production, not which aggregator was chosen.


Decision Drivers (FRs & NFRs)

See SR-011 for the full requirement list.

  • FR-10 (Local Provider Mock): a local mock of the 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 per request.
  • NFR-01 (Per-Endpoint Repository Split): each Shiprocket endpoint is already wrapped by its own repository/shiprocket/ method (per the platform’s layered architecture standard), which is what makes redirecting any one endpoint to a different base URL a configuration change rather than a code change.
  • NFR-02 (Fail-Fast Required Configuration): any per-endpoint base-URL override needed for local/mock routing is a boot-time configuration value, not something discovered missing on first request.

Options Evaluated

Option 1 — Internal mock service, per-endpoint base-URL override (CHOSEN)

Stand up mock-service, a local HTTP host implementing the same endpoints, payload contracts, and status codes shipment-service actually calls, and give each of those calls its own independently overridable base-URL config value (repository/shiprocket/’s IShiprocketRepository is the one abstraction boundary this redirect passes through — the call site never knows whether it’s talking to Shiprocket or the mock).

  • Pros:
    • Zero financial leakage. The state-mutating group (order creation, AWB, label, invoice, pickup) never touches a real wallet in local/CI/most QA use, since each has its own SHIPROCKET_*_BASE_URL override pointed at mock-service.
    • Hermetic, deterministic test runs. mock-service’s X-Mock-Scenario header selects a specific edge case (KYC block, already-assigned AWB, not-found label/invoice, already-scheduled pickup, no-couriers serviceability) on demand, without depending on live network availability or live account state to reproduce it.
    • No live-dashboard pollution. Dummy orders created against the mock never appear in Shiprocket’s own seller dashboard or trigger a real courier pickup request.
    • Read-only/free calls stay live by default, at zero cost. SHIPROCKET_SERVICEABILITY_BASE_URL is left pointed at the real API by default specifically because it has no wallet cost and no side effect — there’s no correctness benefit to mocking a call that’s already safe to make for real, and doing so keeps serviceability results realistic without any extra mechanism.
    • Composes with the existing per-endpoint repository split rather than requiring a new abstraction. Because NFR-01 already put one repository method per endpoint, redirecting any subset of them to the mock is a config change at infrastructure/config.go, not a new adapter layer.
  • Cons & Accepted Trade-offs:
    • Mock/live drift. If Shiprocket changes a response shape or status code, mock-service’s fixtures can silently go stale until someone notices a mismatch — accepted because the alternative (calling live for everything) was rejected for cost reasons, not because this risk is fully mitigated today. Finding (1) and (3) in mock-service’s own documentation are examples of exactly this kind of drift already caught once.
    • The switch is a manual per-environment .env edit today, not an automatic environment-aware selection. Nothing in docker-compose.yml or application code inspects “which environment am I in” to decide mock vs. live automatically — see Technical Debt below.

Option 2 — Call the live Shiprocket API directly in every non-production environment

Skip a mock entirely; every environment, including local development and CI, talks to the same live API production does.

  • Pros:
    • No mock to build or keep in sync with Shiprocket’s real contract — the “drift” risk in Option 1 doesn’t exist.
    • Every test run exercises the actual third-party behavior, with no risk of a mock masking a real integration bug.
  • Cons (Why Rejected):
    • Direct financial cost per test run. Order creation, AWB assignment, and pickup scheduling all deduct real wallet balance — a CI suite running on every pull request would deplete wallet credits continuously, with cost scaling with commit frequency rather than anything meaningful.
    • Real side effects outside the application’s control. An AWB-assigned test order is a real shipment a courier may act on; nothing stops a phantom pickup attempt for a package that doesn’t exist.
    • No official sandbox to fall back to. Shiprocket does not offer an isolated, free integration environment — there’s no way to get Option 2’s “exercise the real behavior” benefit without the cost/side-effect problems above.
    • Non-deterministic, flaky CI. Live network calls introduce rate limits and latency variance into every build; reproducing a specific edge case (KYC block, already-assigned AWB) depends on manipulating real account state instead of a request header.

Final Decision

Option 1 is adopted. Local development, automated tests, and most QA use route the state-mutating Shiprocket calls through mock-service; the two free/read-only calls (auth/login’s OAuth2 token issuance and courier/serviceability) are left pointed at the real API by default, since there’s no cost or side-effect reason to mock them. The redirect mechanism is the existing per-endpoint base-URL config already required by NFR-01’s repository split — no new abstraction layer was introduced to support this decision.

This is a per-endpoint override, not an environment-aware runtime switch — and that is a known gap, not an oversight. Nothing in this stack inspects “local” vs. “CI” vs. “staging” vs. “production” to pick a target automatically; whichever base URL is written into a given environment’s .env is what that environment calls, including production, which simply never has the mock override set. See Technical Debt — Multi-Courier Fulfillment Gaps, TD-04 for the risk this creates and the direction for closing it.