Fl4m3Ph03n1x

Fl4m3Ph03n1x

Processes+messages VS Functional APIs - are they different?

Background

Some time ago I read a huge post about pragmatic Dave and his components idea (along side with a healthy dose of his videos). His idea was that we should code a lot of small applications that communicate together instead of one big app.

Having worked in a lot of monolithic projects (hello C#) this felt like an really good idea to me. Dave went ahead and even made a Components library:

Erlangers

The problem here, if you see the library he made, is that it uses processes for everything.

This is great! I thought. I remember from watching Joe Armstrong that the general idea in Erlang is that processes solve all your problems. If they don’t solve your problems, then more processes solve them. I have even seen old school erlangers advocate that people are usually afraid of harnessing the true power of erlang and that they generally don’t use enough processes.

Of course processes are not good enough, not alone. You also need well defined Protocols to go along. But the main point here is that an architecture based in Processes and Protocols is the preferred way to go with erlang.

Elixirers

But hold on!
If you read the first few threads and responses, you will see that the Elixir community overall prefers a functional approach with functional APIs rather than the processes oriented approach. Proeminent people such as @sasajuric warn about the dangers of using processes and recommend a more pure and functional approach to problem solving, via libraries without state and process trees and well defined APIs.

Basically, if you don’t really need a process, don’t use one.

What do I want?

I can see the value in both approaches. I come from a somewhat functional background but I thought the way to go with Elixir was to embrace the Actor model with all it’s distributed problems, like erlangers do.

So I really don’t understand all the friction with Dave’s idea - it seems rather natural if you come from erlang, right? Or perhaps I am missing an important detail from the discussion?

What is the preferred paradigm in Elixir? Is it the same as in Erlang? Are both communities that different at all?

Most Liked

josevalim

josevalim

Creator of Elixir

I think the assumption that processes+protocols are preferred in Erlang is flawed. If processes and protocols were the way to go in Erlang, we wouldn’t have a gen_server (which is a functional API) as the default way to build processes in Erlang/OTP and used by the majority of the Erlang community.

I believe Joe would like to move more towards processes and protocols and I personally would like to see it explored but we do need some additions in order to make it more productive (and Joe explores some of them in his thesis).

Dave’s approach is functional. A lot of the discussion was when your functional API should be backed by processes or not.

I think both communities would generally agree to not create processes when they’re not necessary. Dave even says so in the readme of his component library:

If you don’t share your state with anybody then good news, you don’t need processes and you don’t need this library (for now). You will live a happier life than the rest of us.

Similarly, Joe is not arguing to use processes for everything. He is arguing to not hide our processes behind GenServer, components, etc. Perhaps they both want to achieve the same goal, which is to streamline the development experience related to processes, but they are approaching the problem in two different ways.

PS: I renamed the title because this is not a discussion about Erlangers vs Elixirists.

11
Post #2
peerreynders

peerreynders

I’m sure he’s going to chime in when he has some time but for the time being I’ll just express my impression as a reader of the book.

There is an expectation that a reader of Elixir in Action may have some OO background and the essence of the message that I received is:

  • Choosing boundaries for processes is different from choosing boundaries for objects/classes.

In particular:

  • Processes are units of computation, messages implementing protocols are coordination - i.e. there is a very clean separation between the computational model and coordination model.

  • OO designed according to CRC leads to very different boundaries for Objects/Classes primarily motivated by encapsulation and while collaboration can be seen as a form of coordination, collaboration tends to happen primarily in the computational domain.

While both have state, processes and objects (classes) are even more different than apples and oranges.

Aside: Process and Stateness are they object? - #8 by peerreynders

10
Post #3
LostKobrakai

LostKobrakai

It feels like you’re takeing the advice @sasajuric has a little to far into a black-or-white area of thinking. From my experience people frown upon using processes for code organisation purposes or data hiding. What processes are advocated for is rather for runtime behavior like isolating errors and organising parts of your system into supervision trees, which allow you to define which parts of your applications can fail independently and which parts need to fail together (e.g. cleanup is needed). Another runtime behavior a process gives you is serialization of requests.

Last Post!

MrDoops

MrDoops

A bit of a tangent, but are there examples of using dependency injection and contracts/behaviours for the runtime behaviour? I’d like to abstractly define the run-time contract such as which messages need to be serialized, what modules and functions are consumed, and then configure the runtime implementation. I’ve found it’s straightforward enough to put Persistence and Query concerns behind an interface or behaviour, but it’d be interesting to do the same with Runtime concerns.

Where Next?

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2976 91332 914
New
f0rest8
Hi everyone :waving_hand: Posting here to showcase and announce that Metamorphic is now officially live on a public-facing domain at htt...
New
andrielfn
Hey there :waving_hand: I want to introduce Fluxon UI, a modern UI component library for Phoenix LiveView that I have been working on fo...
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

Other Trending Topics Top

GenericJam
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
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
webofbits
Squid Mesh is an open source workflow automation runtime for Elixir applications. It is aimed at Phoenix and OTP apps that want to defin...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

We're in Beta

About us Mission Statement