Building an idempotent email API with River unique jobs
Published on: 2025-06-02 09:00:00
We use an email service to send out various River-related notifications. Despite our best efforts setting up SPF, DKIM, and DMARC, we were still getting reports of mail going to spam, so we started looking into alternate mailing providers to see how they'd fare by comparison. Something we noticed while researching is that a shocking low number of them have API facilities to guarantee idempotency — a surprise because email is such a sensitive topic. Not quite as high stakes as charging a credit card maybe, but if a user didn't receive an important email they were expecting, or accidentally received two of them, it'd be at best, annoying.
In case of a communication error between between two services (say River talking to its mail service to send an email), the client can't be sure whether its request was successfully transmitted or not, so it must retry to be sure the operation succeeded. This is best achieved with an API that supports idempotency so that requests after the first don't
... Read full article.