Cars-Island-On-Azure icon indicating copy to clipboard operation
Cars-Island-On-Azure copied to clipboard

Idempotency Concern of the Mail Sender Function

Open NullPointer4096 opened this issue 1 year ago • 1 comments

Description:

I would like to kindly bring attention to a potential issue in the Mail Sender function, which is invoked when a ServiceBus message arrives at the "reservation" queue. This function calls the SendGrid API to send a car reservation confirmation to a customer's email. However, the email sending is not idempotent; Suppose the ServiceBus-triggered function crashes after successfully sending an email (but before acknowledging the ServiceBus that the function has finished), when the function is retried, another email will be sent by SendGrid. In other words, ServiceBus-triggered function has at-least-once execution guarantee, so in this function, email sending could happen multiple times.

Suggested Fix:

Although there's no serious harm in sending two almost identical emails, this duplicate sending due to untimely retries can be prevented. Specifically, SendGrid provides the Email Activity Feed API that one can use to query whether the email has been sent (in a previous execution) before actually sending the email. Suppose the query finds no email has been sent, then go ahead and send the email. If querying the SendGrid service finds the email has been sent, end the execution without sending the email again.

Thank you for considering this issue. I hope this suggestion could help improve the idempotency and user experience of the Mail Sender function. Please feel free to reach out if you have any questions or concerns.

NullPointer4096 avatar Apr 16 '23 19:04 NullPointer4096

Hi @NullPointer4096,

Thank you so much for the suggestion. This is really helpful and I agree that even if this is not a big problem it would be nice to enhance the mail sender function functionality. If you have some time, would you be able to provide some PR with changes? Even if not, this is great suggestion for others to know, thank you once again!

Daniel-Krzyczkowski avatar Apr 18 '23 04:04 Daniel-Krzyczkowski