2 ms·
I don't know how it's done now or what APIs support, but here's an old-school design: During the first database commit, set a field indicating that the associa
by skybrian 5y ago
I don't know how it's done now or what APIs support, but here's an old-school design:
During the first database commit, set a field indicating that the associated email is pending. After sending it and getting a success, do another database commit setting the flag to sent.
You will need a server-side task, maybe a cron job, to periodically query the database for pending emails and attempt to resend them, then set the flag to sent. Also, hopefully the API you use to send email has a way to avoid duplicate emails, perhaps by attaching a unique ID to the request that's used to detect duplicate sends.
- vsroy 5y ago> Also, hopefully the API you use to send email has a way to avoid duplicate emails, perhaps by attaching a unique ID to the request that's used to detect duplicate sends. I think this is the interesting part. Storing a value in the table to be processed by a queue seems normal / not rocket science. But what happens when we 1. Call the API 2. The API succeeds 3. We crash before we can write success Now we'll send duplicate emails. I don't think all APIs have ways to avoid duplicate emails/transactions, so that could be a hairy problem.
- skybrian 5y agoUnless you use an API that supports duplicate request removal, either you drop some emails (at-most-once delivery) or sometimes you send duplicates (at-least-once delivery). For email, I think the occasional duplicate is usually better. (Effectively, it's up to the email recipient to ignore the duplicate.)