Skip to main content
HomeBlogGuidesShipment Tracking Webhook Payloads: How to Store Checkpoints without Duplicates

Shipment Tracking Webhook Payloads: How to Store Checkpoints without Duplicates

17TRACK

To store shipment tracking checkpoints without duplicates, save each webhook delivery durably, then insert its checkpoints using a stable identity and a database uniqueness constraint. Treat webhook delivery IDs and checkpoint IDs as different things: a retried delivery may contain several checkpoints, and a later delivery may repeat checkpoints you have already stored. A unique index makes the final decision safely even when two workers process the same shipment at once.

Shipment Tracking Webhook Payloads How to Store Checkpoints without Duplicates

This guide is for developers building a tracking integration or maintaining the shipment history behind an order-management, customer-support, or notification system. The goal is a history that preserves real tracking events without showing repeated scans or sending duplicate alerts.

Understand what can repeat

A webhook payload is a message about a shipment, not necessarily a single new checkpoint. Depending on the provider and event type, it may contain one checkpoint, a list of recent checkpoints, or a refreshed shipment history. A later payload can therefore include both a new scan and older scans your system has already seen. Retries and concurrent processing create further opportunities to insert the same information twice.

Keep three identities separate:

  • Shipment identity: Which shipment record should receive the checkpoint? Resolve this within your own account or tenant boundary. A tracking number alone may not be an adequate database key.
  • Delivery identity: Have you already accepted this particular webhook message? Use a provider-supplied event or delivery ID if the integration documents one.
  • Checkpoint identity: Does this scan already exist in the shipment history? Prefer a documented, stable checkpoint ID when one is available.

Deduplicating only deliveries is insufficient if separate deliveries contain overlapping histories. Deduplicating only checkpoints can prevent repeated scans, but it does not give you a reliable record of which messages were received, accepted, or left unprocessed. The two controls solve different problems.

Inspect the payload before choosing a key

Start with the actual webhook documentation and sample messages for your integration. Record where the provider places its shipment identifier, carrier identifier, event ID, checkpoint ID, event time, status code, location, and descriptive text. Also check whether a payload is a single event or a shipment snapshot, whether fields can be absent, and whether an existing checkpoint can later be corrected. Do not assume that a field called timestamp is the carrier's scan time; it might describe when the provider sent the message.

For a 17TRACK Tracking API integration, use the official API documentation and the payloads delivered to your account to establish those field meanings before mapping them to your tables. The identity and storage pattern below is provider-agnostic; its example field names are illustrative, not a claim about 17TRACK's webhook schema.

Capture the original payload, or an appropriately protected representation of it, alongside parsing and processing metadata. This makes a field-mapping mistake repairable: you can reprocess an accepted message after fixing the mapper instead of reconstructing the shipment history from rendered UI text. Set retention and access rules for raw payloads because shipment data can contain personal information.

Choose checkpoint identity in order of reliability

The strongest practical key is a checkpoint identifier that the provider documents as stable across retries and subsequent payloads. Scope it to the appropriate provider, account, and shipment. Verify its documented uniqueness scope rather than assuming that a short ID is globally unique.

If no stable checkpoint ID is available, derive a fingerprint from the fields that define a distinct scan in your integration. One possible tuple is tenant + shipment + carrier + event_time + carrier_event_code + normalized_location. Hashing that tuple produces a compact key, but the hash does not make a weak tuple reliable. Two genuine scans might share a time and status, while one genuine scan might appear twice with slightly different location text. Use a fallback key only after checking real payloads for both kinds of collision.

Prefer a documented event code over display text where possible. Labels can be translated or revised without changing the underlying event. Normalize only what you understand: trimming whitespace and standardizing known code formats may be appropriate, while aggressively removing location detail can merge separate scans. Preserve the original values in separate columns for auditing.

Time needs particular care. Store an event instant in a timezone-aware form when the source supplies enough information, and keep the original timestamp string. RFC 3339 describes a widely used Internet timestamp format, including timezone offsets; it does not resolve a source timestamp that arrives without a timezone. If the provider cannot distinguish carrier event time from message time, do not silently substitute one for the other in your fingerprint.

When the available fields cannot reliably distinguish checkpoints, do not promise exact deduplication. Preserve the records and flag ambiguous matches for review, or apply a documented business rule that accepts the possibility of merging genuine scans. A visible duplicate is often easier to correct than a distinct carrier event that was silently discarded.

Use durable storage and a unique constraint

A useful design has an inbox table for accepted deliveries and a checkpoint table for shipment history. In the inbox, store the provider, tenant, delivery ID when available, receipt time, protected raw payload, and processing state. In the checkpoint table, store the internal shipment key, source, checkpoint key, original fields, parsed event time, and ingestion time. Keep the source checkpoint key distinct from any internal row ID.

The checkpoint table should enforce uniqueness over the scope in which the key is valid. For example, if the source checkpoint key is unique only within a shipment, the unique constraint should cover (tenant_id, shipment_id, source, checkpoint_key). If you generate fallback fingerprints, record how the fingerprint was constructed so a later mapping change does not silently change the meaning of stored keys.

Insert checkpoints with a conflict-aware statement rather than checking for an existing row and then inserting. In PostgreSQL, a unique constraint combined with INSERT ... ON CONFLICT DO NOTHING lets the database arbitrate concurrent inserts. A prior SELECT is not a substitute: two workers can both observe that a row is absent. If the source supports checkpoint corrections, decide which fields may be updated and under what evidence; DO NOTHING alone will not apply a legitimate correction.

A practical processing sequence is:

  1. Authenticate the incoming request using the integration's documented mechanism. Apply request-size and parsing limits before expensive work.
  2. Persist an inbox record and the payload before reporting successful acceptance, or durably enqueue it under an equivalent arrangement. If durable acceptance fails, return an error rather than claiming the message was received.
  3. Resolve the shipment within the correct tenant. If the reference is missing or ambiguous, retain the inbox record for investigation instead of attaching scans to a convenient-looking shipment.
  4. Extract each checkpoint, validate the fields needed for identity, and calculate its checkpoint key. Process every item in a snapshot; do not assume the first item is the only new one.
  5. Insert checkpoints under the database unique constraint. Record whether each was inserted, matched an existing record, rejected as invalid, or held for review.
  6. Mark the inbox item processed only after its intended database changes have committed. Drive downstream notifications from newly accepted checkpoint changes, not directly from every received payload.

Keep acknowledgment behavior aligned with the provider's documented retry rules. For example, accepting a message into a durable inbox can justify an HTTP success response even if a background worker has not finished parsing it. If the payload exists only in process memory, returning success risks losing it when that process stops. A duplicate delivery should normally be treated as already accepted after its identity is confirmed, not as a reason to repeat notifications.

Handle updates, order, and side effects separately

Shipment history is not always received in scan-time order. A checkpoint created earlier may arrive after a later one, and a provider may revise a status description or location. Store both event time and ingestion time. Sort the visible history by an explicit rule, and avoid treating the latest webhook arrival as proof that its status is the shipment's latest physical event.

For a checkpoint with an existing key, define one of three policies: ignore exact repeats, update permitted fields when a documented revision is received, or retain a versioned correction history. Which policy is appropriate depends on the source's guarantees and what your users need to audit. Do not overwrite the original checkpoint solely because a later payload contains a different display label; first determine whether it represents a correction or a mapping difference.

Notifications need their own idempotency rule. A unique checkpoint row prevents duplicate history entries, but a worker can still send an alert and then fail before marking it sent. An outbox record tied to a newly stored checkpoint gives you a durable place to track the intended side effect. If the notification destination supports an idempotency key, use one; otherwise design for the possibility of retrying a send. Database deduplication alone cannot guarantee exactly-once delivery to an external service.

Also avoid reducing the entire shipment to a single status by comparing webhook arrival times. A shipment's current display status may require carrier-specific interpretation, especially when scans arrive late or describe exceptions. Keep checkpoint storage separate from the rule that derives a summary status.

Test the failure cases, not just the happy path

Before enabling notifications or customer-facing timelines, replay representative payloads against a test database. Include an identical delivery received twice, two different deliveries with overlapping checkpoints, and two workers inserting the same checkpoint concurrently. Each should leave one stored row for each genuinely distinct scan.

Then test a snapshot with several checkpoints, an older scan arriving late, two scans with the same status and timestamp, missing or malformed event times, a corrected checkpoint, and a tracking number that exists in more than one tenant. Check both the final rows and the side effects. A test that only counts webhook requests will not reveal duplicated alerts or a scan merged under an overbroad fingerprint.

Monitor accepted deliveries, processing failures, duplicate-key conflicts, ambiguous fingerprints, and checkpoints that cannot be matched to a shipment. An increase in duplicate conflicts can be normal when snapshots repeat history; an unexpected change in that rate can also reveal a provider payload change or a broken key mapping. Keep enough source data to investigate before changing the normalization rule in production.

FAQ

Can I deduplicate on tracking number and status?

Not safely in general. A shipment can have multiple genuine checkpoints with the same broad status. Use a documented checkpoint ID if available; otherwise evaluate a more specific composite identity using actual payloads and document its collision risk.

Should I hash the entire webhook payload?

A whole-payload hash can identify an identical message body, but it does not identify a checkpoint repeated inside a later payload with other new data. It can also change when field order, metadata, or display text changes. Keep delivery-level and checkpoint-level deduplication separate.

What should happen when a webhook has already been received?

If the previously accepted delivery is durably recorded, do not process its side effects again. Follow the provider's documented acknowledgment behavior, and make sure an inbox record marked as accepted is not hiding an unfinished processing task.

What if a checkpoint has no reliable ID or timestamp?

Store enough original data to investigate it. Use a cautious fallback only if testing shows that its fields distinguish real scans adequately. Otherwise hold ambiguous records for review rather than silently merging them.

Does a unique database key prevent duplicate customer notifications?

It prevents duplicate checkpoint rows within its defined scope. Notifications are a separate side effect and need their own durable state and retry policy, such as an outbox tied to a newly inserted checkpoint.

Sources