How to design a CloudEvents contract for shipment webhooks
Use the CloudEvents envelope to identify and route events, and document the freight payload separately. Use the event origin and event ID for deduplication; use a shipment or leg reference to associate multiple events with the same movement.
Agree which changes require a new contract version.
The CloudEvents specification requires source, id, specversion and type. The source and ID together distinguish an event. Document the event type, payload schema, status vocabulary and delivery guarantees independently. CloudEvents does not itself establish that a webhook is authentic or provide exactly-once delivery.
Two carrier systems both send event 42.
In a synthetic webhook feed, carrier A and carrier B both publish ID 42 from different sources. Treat them as distinct events. If carrier A redelivers the same event, avoid repeating a side effect. If a redelivery has different content for the same source and ID, flag the contract conflict rather than silently accepting it as a new status.
Test idempotency, access and ordering separately.
- Validate the authenticated sender and its allowed source scope before trusting the declared source.
- Test a delayed pickup event arriving after delivery. Arrival order alone must not undo the current projection.
- Verify that an unknown payload version can be held for review without being treated as an accepted business event.