I’ve written a short blog post about what I learned building simple email features for a web server written in the Dream framework. The accompanying source code is available here:
I’m interested in adding more examples and tutorials to the OCaml ecosystem and would be happy to get your feedback, positive or negative, on this write-up (here or via email/github/discord).
Thank you for the blog post and the example code—these kind of examples are very valuable!
In my tests, a successful API request typically took between 0.5 and 1 seconds. For comparison, the webserver can serve the email form in less than 200 microseconds, so the performance benefits to shifting email tasks to a background queue are nontrivial.
The way I read the example code, since the API request (to Mailgun) is asynchronous, that means it is not blocking the webserver from serving requests. But the other example you mentioned—rendering an image (using server’s CPU)—would be indeed blocking and have to be offloaded to a worker.
Thanks for your feedback, I should clarify that in the post. In past products I’ve worked on, when we created custom emails with account-specific images, the background worker process was responsible for both generating the image and then sending the email. So you’re right, none of that workload should fall on the webserver.
Hey, interesting post. I had a couple of code suggestions. May I send a PR with my changes to start a discussion? (Not necessarily for the purpose of merging.)
I decided to use RabbitMQ because I didn’t want to tie my implementation to one cloud provider and RabbitMQ is supported by amqp-client on OPAM
What do you think of using something simpler, like a table in a SQLite file?
This is an excellent blog post, and I learned a lot from it.
Apart from benefitting as a reader, this also just considerably sped up my side of helping to design email support for Dream. Thanks for all the links inside the post, and alternatives mentioned!