NinekoTheCat
Why isn't the actor model used in the wild?
I am learning elixir, and I am looking everywhere but for some reason the… actor model isn’t used at all?
There’s no other processes aside from… endpoints and repos??
here there’s a bit more child processes but like… why isn’t there more??
Most Liked
dimitarvp
You are making a very classic mistake here – you are trying to find a simple formula.
There is no simple formula though.
The actor model (Erlang processes) is about being able to model runtime entities. Which entities, how many, and when are they spawned depends on your business requirements.
Actors are just one more tool in your belt.
This article might help a little bit: The Erlangelist - To spawn, or not to spawn?
But again, don’t expect a simple formula.
That’s part of the entire answer – and here the partial answer is “yes”.
But there’s also the aspect of “I want to control access to a resource” (you already mentioned locking) and “I want to make sure this entity receives messages only one by one, sequentially” (what GenServers do).
benwilson512
Actors in Elixir generally map to runtime subcomponents of the system, not business entities. So for example when using phoenix channels or live view every connected page is an actor that manages messages in and data out, but then the business logic processing on that data favors functional data patterns.
dimitarvp
Well, roughly – yes, that’s one factor.
But there’s more to it. So imagine your app is for example about reserving hours to doctors. And in your controller you have to consult a 3rd party API (for example Microsoft Calendar).
- If you want to give people immediate confirmation or rejection, you do the 3rd party API call (a network request) inside your controller function without spawning a process, so your customers will have to wait in the browser until that request completes.
- If you opt for customers to never wait you will spawn this 3rd party network API call in a new process and immediately return something to the customers like “We have requested reservation of the hours of this doctor. You should receive an email within a few minutes telling you if the hours are free.”
As you can see, this is not about the technical capabilities, this is about what the business wants.
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









