Get the latest tech news
Building an idempotent email API with River unique jobs
Using unique jobs in River to build an email API that takes an idempotency key so that even in the event a request needs to be retried, it never sends a duplicate email.
Mutations like PUT or DELETE take more care than read, but especially when using an ACID database like Postgres, idempotency is usually very achievable as long as all changes happen in one transaction. Hopefully all responsible users will be generating V4 UUIDs that will statistically never collide with anything else, but bugs or malicious behavior could lead to duplicated keys, at which point scoping them to specific accounts becomes important, so our uniqueness is based off AccountID+ IdempototencyKey. As an additional safety feature, the API will return an error in case incoming parameters didn't match those that created an existing job.
Or read this on Hacker News