MatijaL

MatijaL

When should I start using more advanced Elixir features like OTP, Genservers, etc

Hello,

so, I’ve been learning Elixir and Phoenix for some time now, I’ve built some web apps for practice(CRUD), used Ecto quite a lot, just started playing with LiveView etc. There are more advanced Elixir features and concepts like protocols, OTP, Genservers… when should I start learning those? Do I even have to learn them? Everything I’ve built so far was without them and I don’t really understand where exactly those advanced features come in.

Thanks

Most Liked

christhekeele

christhekeele

I’m a big fan of shallow/wide learning. I recommend learning just enough about them to know, when a specific problem comes up, whether or not they are a good fit for it; then coming back to the tool when you’ve decided you need it and need to learn more.

This is, of course, easier said than done, and when to “call it quits” when studying something is heavily dependent on your personal learning style.

Personally, I feel confident enough in classifying a concept as “sufficiently understood for evaluation later” when I’ve read enough about:

  1. How it is meant to be used
  2. What it is good at
  3. What it is bad at

It’s normally this last point that is difficult to surface. Very few libraries spend a lot of time polishing a description of what they suck at, so I really like to hone in on things like post-mortems and the ‘x’ in “we migrated from x to y” blog posts, to learn from other’s mistakes before making them myself. (In fact, I’m often more ready to adopt a tool that has a lot of stories of switching off of it—it makes me feel more confident in knowing when it is a poor choice, so I get to make better ones!)

I’m confident enough in my abilities and the excellent quality of documentation in this community to trust that if I can recognize the utility and trade-offs of a tool, I can navigate the implementation details when I decide it is time to reach for it.

hubertlepicki

hubertlepicki

You can improve this by starting the Tasks under DynamicSupervisor, with restart: :temporary, and monitor the Task’s pid instead of linking to get notified when the process finishes or crashes (and what was the exit value/reason).

Further, if you need retries, you can use a different restart strategy on the supervisor and introduce an additional process, whose job is to start and monitor the Tasks, and provide responses in case these finally crash after N restarts and the job can’t be completed.

Then, if you want to limit the concurrency, you can introduce max_children for the DynamicSupervisor, and then queue up the calls somewhere (the new process from above paragraph can do it) if they’re coming in and the capacity is exceeded, and you just built yourself an in-memory queue system with a pool of N workers, retries and error handling.

LostKobrakai

LostKobrakai

Alternatively there’s Task.Supervisor implementing most of that already within the abstractions of Task.

Where Next?

Popular in Discussions Top

andre1sk
A big advantage to Elixir is all the distributed goodness but for many applications running on multiple nodes having integrated Etcd, Zoo...
New
Jayshua
I recently came across the javascript library htmx. It reminded me a lot of liveview so I thought the community here might be interested....
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
IVR
Hi all, I’ve seen a number of related threads in the past, but I’d still be very curious to hear an up-to-date opinion on this topic. I...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
jesse
Hi everyone, I hesitated to post this here because I don’t want you to think I’m spamming, but I’ve been working on a Platform-as-a-Serv...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
kostonstyle
Hi all How can I compare haskell with elixir, included tools, webservices, ect. Thanks
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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 30877 112
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
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
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New

We're in Beta

About us Mission Statement