venomnert
Hey Everyone, hope everyone had a great Christmas and successful boxing day
!
Context:
I want to each client to to be able to create send multiple emails. After multiple iterations I have landed on the following designs; furthermore, have settled on Tasks.
Questions:
-
Just out of curiosity, when would the GenServer be more beneficial than Tasks, based on the design?
-
The main benefit GenServer provides is the ability to maintain long running state. Apart from that are there any performance benefit that GenServer offers over Tasks?
Trending in Discussions
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
You have a better control with GenServer, while Task is a process meant to do something, then die.
But if it is just to send an email, You could just spawn a process, then You could ask why a Task over a Process?
One day You might decide to have a better control, a better error handling, or just support back pressure… You might send billions for Christmas, and less the rest of the year. In this case I would not choose Task.
benwilson512
@kokolegorille are you confusing Task with a job queue? A task is literally just a process. It doesn’t provide better control or back pressure, it provides marginally better error handling because it sets some standard values in the process dictionary, but that’s about it. It isn’t heavier weight than a process.
On the note of a job queue, those are often a good idea with something like email. You get retries, concurrency limits, and so on.
kokolegorille
I mean backpressure with GenStage, or related. Under the hood, they are specialized GenServer.
Sorry if it was confusing. I wanted to tell every processes are equals, but some are more controlled than the others.
LostKobrakai
Tasks are most useful for failure separation or asynchronous execution for a piece of code. If your current process does need to do something, which is prone to fail, possibly even because of things outside of your control, but hopefully in the control of your user, then Tasks are a good way to start. Same if you want to quickly execute something concurrently to your current process, where persistance of the job doesn’t matter. All a task does is basically inline executed code, but wrapped in another process. Only the process starting the task should be interested in the result or failure of the started task – with the only exception being the optional task supervisor. Personally I’d even say a task should not be very long running as well, because it’s unlike a job queue not sticking around in case of it being stopped by external factors.
I’m with @benwilson512 here, that for emails a proper job queue is a better fit, because you can be more certain that the email will indeed be sent. Sending emails are something once the initial webrequest is successful your system is in charge to fulfill.
Tasks imo are more useful for code, where your system is not in charge if there are failures. E.g. take processing an user uploaded file. If the processing fails (and your code works correctly) your system cannot do anything to make it work. The user needs to fix the input from their side.
I’d like to make this a bit more concrete. A task is meant to be an alternative to using
spawn, but be otp conform (see:proc_lib), so it can be properly supervised/shut down. With that it’s less likely to leak processes with tasks. A task therfore is more than “just a process” given it implements otp’s messages, but it’s likespawnjust meant to execute a piece of code and be done.venomnert
Very well explained @LostKobrakai! Thank you @benwilson512 and @kokolegorille for your inputs as well
ityonemo
There’s also some elixir-only goodness in there with the
:$callersstuff which makes async unit testing with Ecto, Mox, Hound, Wallaby, etc. effective.In short, “almost always use Task over spawn”.
mgwidmann
One limitation I ran into using
Task.async_stream, one slow process will stop the processing of future work. Say you have 1000 items and number 30 takes significantly more time than the rest (as is with email commonly), processing at a concurrency of 8 for example the 39th task won’t be executed because it will be waiting on the 30th to complete. This happens because theTask.async_streamfunction ensures ordering, using a selective receive against the PID.Therefore, unless the time to process a particular task has a particularly low std dev, it will be more efficient to build your own solution. This all assumes you’ve got the load to justify of course, otherwise they may seem the same in a low volume system.
axelson
If you don’t want this behavior you can set
orderedtofalseand then the output will not be buffered at all.