Trace
Back to blog

Product

How to Reduce Package Tracking API Costs Without Missing Delivery Updates

Control tracking API spend with state-aware polling, caching, webhooks, deduplication, active-shipment windows, and usage metrics that preserve customer experience.

20 September 202613 min read

Tracking cost grows with requests, not with customer value. A shipment might receive six meaningful scans while a naive system requests it hundreds of times. The gap is avoidable: ask more often when change is likely, reuse fresh answers, and stop asking when the shipment reaches a terminal state.

This guide provides a cost model and an implementation strategy that preserves timely delivery updates. The goal is not the fewest requests; it is the lowest cost per useful status change.

Calculate the naive baseline

Multiply active shipments by polls per day and average days in transit. Ten thousand shipments checked every 30 minutes for five days produce 2.4 million lookups. Most return the same answer as the previous call.

Now measure meaningful changes per shipment. If a typical parcel produces eight distinct events, the useful information is tiny compared with the request volume. That ratio gives the team a concrete optimization target.

Poll according to state

Pending shipments change slowly after label creation, so check them every few hours. Active in-transit shipments can use a moderate interval. Out-for-delivery and urgent exceptions deserve a shorter interval. Delivered and returned shipments should leave the polling queue entirely.

Add jitter to every schedule and back off after unchanged results. A state-aware queue reduces spend and prevents synchronized spikes without making the customer page feel stale.

function nextPollMinutes(status: string, unchangedChecks: number) {
  const base = {
    pending: 240,
    in_transit: 90,
    customs: 180,
    out_for_delivery: 30,
    exception: 60,
    delivered: Infinity,
  }[status] ?? 180;

  return Math.min(base * Math.pow(1.4, unchangedChecks), 720);
}

Cache by tracking identity

A customer refresh, support-agent view, notification worker, and analytics job may request the same parcel within minutes. Put a shared cache between product traffic and the provider so those reads converge on one lookup.

Expose cached and last_checked_at in your internal response. Product surfaces can then show exactly how fresh the status is and request a refresh only when policy allows it.

Use webhooks for change, polling for reconciliation

Webhooks reduce the need to ask whether anything changed. They are not a complete replacement for polling because endpoints fail, providers delay events, and some sources are pull-only. The reliable design uses webhooks for speed and a slower reconciliation schedule for completeness.

Deduplicate webhook and polling results through the same event fingerprint. Otherwise two delivery paths can create duplicate notifications and misleading usage analytics.

Track only active business windows

Do not start high-frequency tracking at label creation if fulfilment takes two days. Do not continue after delivery merely because a recurring job still sees the row. Define an active window from expected carrier acceptance until a terminal state plus a short confirmation period.

Archive or cool down abandoned labels, test numbers, cancelled orders, and stale imports. These quiet records are easy to miss and can consume a surprising share of volume.

Protect against accidental traffic

Monthly quotas and per-minute limits are operational safety controls, not only pricing gates. Add idempotency to job creation, cap batch sizes, detect retry loops, and alert on sudden changes in lookups per active shipment.

Break usage down by API key and environment. A forgotten staging worker should be visible before it spends a production budget.

Measure cost per useful outcome

Monitor lookups per shipment, cache hit rate, percentage of calls that produce a new event, webhook delivery success, and cost per delivered shipment. Pair those metrics with freshness so savings do not hide a degraded customer experience.

Trace includes a 30-minute response cache, normalized terminal states, usage visibility, and webhook delivery across every plan. Those primitives let a small team build a cost-aware loop before volume turns waste into a budget problem.

Build tracking into your product

Create a Trace account, generate an API key, and test package tracking from the dashboard.

Continue reading