Why stateful when you have databases?

It would be a bad idea to mimic what database are good at with distributed nodes… but sometimes the source of truth is not the db. It’s just more efficient when you don’t need to encode/decode data and keep it into processes.

For example when the state is ephemeral, like the state of a game, or a chat. With websockets, You can talk to the server directly, You would not want to persists this communication into db.

When using Rails, I had the bad habit to design system around database.

With Elixir, You have plenty of options (processes, ets, dets, mnesia, etc). And the possibility to use term_to_binary, binary_to_term to persists any complex structures into almost anything.

See this post.

10 Likes