ScriptyScott
Clarification on Sending Emails Asynchronously
Hey Folks,
Quick question, while implementing email functionality into my Phoenix App I came across multiple sources that claim:
Opposite to some stacks, sending emails, talking to third party apps, etc in Elixir do not block or interfere with other requests, so you should resort to async emails only when necessary.
This seems so foreign to me, coming from other platforms like Rails. Can someone briefly explain why this is the case in Elixir and what specific scenarios require async emails/calls? I love how responsive Phoenix and LiveView Apps are and would hate to loose that with a call that blocks the UI.
Thanks,
Scott
First Post!
josefrichter
I think it refers to the fact that every single connection is handled by a separate independent process, so a slow operation, or even a crash, does not slow down or directly affect any other connection. I think this is a good explanation what’s going on under the hood: https://elixir-lang.org/getting-started/mix-otp/task-and-gen-tcp.html
But I’d too like to see a confirmation or more profound answer from some of the OGs here ![]()
Most Liked
benwilson512
Nicd
dimitarvp
It goes even further than that. Elixir’s processes are not only OS threads; you can still have tens of thousands of processes and parts of them might be stuck (and that count can be much more than the amount of CPU cores) but the rest will still continue running.
Last Post!
derek-zhou
Of course. My point is, if it is something I depend on, I’d like it to fail flat on my face if it ever fails.
Case in the point: A few year ago, I have a system that often failed to deliver emails that contained the one time code for login purpose. (It was mis-configuration of some sort) I was grilled for it badly.
To recap, there are 3 ways to send emails:
- just send it in process
- spawn and send
- throw it out to a background job with pubsub, or oban if I want scalability or persistence across reboot.
1 has the easier error handling and is often fast enough. 3 has the latency and throughput advantage, 2 has none.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










