Your consumer sends a confirmation email through a provider that has no idempotency key. At-least-once delivery means some customers get two. What are your options?
Sketch your own answer first, then compare it with the one below.
A strong answer
The crash window cannot be closed completely when the provider cannot dedupe, so the real question is which error you prefer and how much you can shrink it.
Record intent before sending. Write a row for the message id with state pending, send, then set sent. On redelivery the consumer reads the state. If it is sent, skip. If it is pending, the previous attempt may or may not have gone out, and that is the gap. For an order confirmation I would send again and accept a rare duplicate. For something harmful to repeat, I would not send and would flag it for review.
Shrink the gap by keeping the pending-to-sent window short and the ack timeout longer than the provider call, so slow calls do not trigger redelivery. Use the provider's message id or delivery status, where there is one, to check whether the pending email went out.
Finally, decide the policy by cost. A duplicate confirmation is an annoyance, while a missing one may cause a support ticket. Write the choice down, and count duplicates so the rate is known.
Sources
- Brandur Leach (2017). Designing robust and predictable APIs with idempotency.
- J. H. Saltzer, D. P. Reed, D. D. Clark (1984). End-to-end arguments in system design.