3 ms·
I would like to see the code for the chat or presence server. I have a hunch it will look different depending on the experience of the programmer. I'm especial
by z3t4 11y ago
I would like to see the code for the chat or presence server. I have a hunch it will look different depending on the experience of the programmer.
I'm especially interested in how they manage state. Because when you do not have to manage state, everything becomes easy and scalable.
With state I mean for example a status message for a particular user.
- lucaspiller 11y agoState is one of the big differences between CGI-esque scripting languages and how things are usually done in Erlang. As processes are cheap, one way is to fire up a session process for each user that connects to the system, and keep this around for the lifetime of their session. The process will hold within it any state that is needed between requests, without needing to refer back to the database every time. Whenever a request comes in, you then route the request to that session process (even when it's on another physical machine). This not only provides a clearer mapping between your external and internal APIs, but also allows you to fairly easily ensure that a user can't perform concurrent actions. Edit: Not sure if that's exactly what you mean, so let me know if you have more questions :)
- yelnatz 11y agoThe Phoenix Framework (web framework for Elixir) already solves this for you.[1] It's called Phoenix.Presence. They used a combination of CRDTs with heartbeats to implement it. You are right, it is a hard problem because of the distributed nature of Erlang/Elixir. That's why Chris provided a framework level solution for it. [1] https://youtu.be/XJ9ckqCMiKk?t=921 https://youtu.be/XJ9ckqCMiKk?t=921 (Erlang Factory SF 2016 Keynote Phoenix and Elm – Making the Web Functional)