ScriptyScott

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.

Taken from the Swoosh Hexdocs

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

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 :slight_smile:

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

https://www.youtube.com/watch?v=JvBT4XBdoUE is a classic talk that covers these cool properties.

Nicd

Nicd

You may also be interested in the BEAM Book (linked the scheduling chapter directly) if you want to know more about the internals.

dimitarvp

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

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:

  1. just send it in process
  2. spawn and send
  3. 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.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement