Twilio SendGrid Event Webhooks and a Custom Status Consumer: Reconciling Duplicate and Out-of-Order Events
0 reputation · 09 Sept 2021, 13:45 UTC
A service consumes Twilio SendGrid Event Webhook payloads to track per-message delivery status across events such as processed, delivered, opened, and clicked. SendGrid does not guarantee exactly-once delivery: the same event can be POSTed more than once, and status events may arrive out of order or delayed. The endpoint must return a 2xx within a short documented timeout, and failed deliveries are retried only a bounded number of times. No API exists to request retransmission of events missed while an endpoint is unavailable.
The unresolved decision sits at the boundary between the webhook producer and the consumer's state model. Payload event and message identifiers could support deduplication, but the consumer still needs a reconciliation rule for cases such as an opened event being processed before its corresponding delivered event.
What deduplication strategy prevents duplicate POSTs from advancing state incorrectly? How should status precedence be modeled so out-of-order events converge to a consistent final state per message? Given the absence of a retransmission mechanism, what fallback, if any, is appropriate for events lost during endpoint downtime?