Rule
Message sends must be deduplicated by a stable send key before delivery.
Why
Queue retries, job replays, and worker crashes can cause the same message to be sent multiple times.
Must
- Compute a deterministic send key from (recipient, template, campaign, date-bucket).
- Check the send key against a sent-messages record before dispatching.
- Record the send key atomically with the dispatch call.
- Expire send keys after a deduplication window (24-72 hours).
Should
- Use a unique message ID provided to the carrier so they can also deduplicate on their end.
- Log duplicate sends as a metric and alert on spikes.
Anti-patterns
- Deduplicating only at the job level with no send-layer check.
- Send keys that include a timestamp component shorter than the dedup window.
Test Cases
- Replaying the same send job twice delivers one message.
- Expired send key allows re-send in the next dedup window.
Telemetry
- message_send_deduplicated
- message_send_dispatched
- deduplication_spike_alert